1

I'm building an artgallery using Page Manager and Panels in Drupal 7.

A piece of art in the gallery is a node type and each one is related to a period of time, which is also a node type.

When viewing a page displaying a period of time, I need a link that takes the user to all the pieces of art relating to that period of time.

So I have made a view, that uses the nodeid of a timeperiod as a contextual filter, and gets all the artwork nodes, that are related to that particular timeperiod node.

The question is, when on the page for the timeperiod, how do I grab the nodeid of that particular timeperiod and dynamically generate a link to a page where the current nodeid is passed as an argument? (So that the correct pieces of art are fetched with the view).

acrmuui
  • 2,040
  • 1
  • 22
  • 33
  • Which template are you trying to get the node id in to? Page.tpl.php? – Rawkode Dec 07 '12 at 12:30
  • Have a look at the [Entity Reference](http://drupal.org/project/entityreference) module, it will formalise the relationship and provide the links to the referenced content out of the box – Clive Dec 07 '12 at 12:39

1 Answers1

4

You can use arg(1) in a piece of custom code to get the current node id (but only if it is a node you're on). See http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/arg/7. For instance you could easily embed your view in a template of your choice or a within a theme function like this:

views_embed_view('name_of_your_view', 'display_name', arg(1));

where the third parameter is the argument, the node id of your current (timeperiod) node. See http://api.drupal.org/api/views/views.module/function/views_embed_view/7.

To just place a link on that timeperiod node to that page (generated by your view) you would probably use a preprocess function in conjunction with a template (print if set). The possibilities there are uncountable, so you might need to provide further informations, where to place the link. But basically it can be achieved by using `arg(1)'.

Knörpeltäng
  • 453
  • 1
  • 3
  • 15