gables20
gables20

Reputation: 496

passing cck field as an argument in views

I have content type called event, which has a cck field called event id. The idea is that once a user goes that a url with that id, only information relating to that event id is displayed. In my view, i tried creating a block view and passed the event id as an argument, as soon as i do that, the results which formerly displayed in the live preview disappears..Not quite sure of what i am doing wrong, or if i should be block view. Should this be a page view? Please help.

Upvotes: 0

Views: 765

Answers (1)

GeoChatz
GeoChatz

Reputation: 668

I believe that you should create a Page View and not a block view. You have to pass a argument. Is Event ID equals to NodeID? If yes then you should add an Argument of type Node:NID and then set "Provide default argument" equals to "Node ID from URL".

If the EventId is NOT the NID then you should set the Default Argument to PHP and give the following PHP :

$path = drupal_get_path_alias($_GET["q"]); //get the URL alias
$path = explode("/", $path); //break path into an array
if ($path[0] == "events" && $path[1] != "")
{
  return $path[1];
}

The above code will take the argument from the URL (the URL should be like www.example.com/events/14555

The reason that I am using the drupal_get_path_alias is because you may have enabled the pathauto module. If not you can just give the following php

if (arg(0) == ‘events’ && arg(1) != ”) return arg(1);

Upvotes: 1

Related Questions