I've set up the default Flag (bookmark) and have added the proper links to my node.tpl.php pages so that the flags show up properly. Is there any way to add the same link to a rendered view (page?) I tried using views-view.tpl.php and adding the following code:

<?php print flag_create_link('bookmarks', $node->nid); ?>

But that doesn't work because the rendered view is not a node, of course. What I'm trying to do is allow users to bookmark a rendered page view just like they can do with any other node.

  • is your view of fields? (can you add fields?)
    – No Sssweat
    Mar 2, 2016 at 22:39
  • Yes, it is -- but I'm not looking to add a flag to each item, rather I need one flag for the entire page. Mar 2, 2016 at 22:40
  • but I'm not looking to add a flag to each item what is your view displaying? multiple nodes? or only 1 node?
    – No Sssweat
    Mar 2, 2016 at 22:42
  • Multiple nodes -- news articles, in this case. Mar 2, 2016 at 22:52
  • so you want the flag for the page you're on, or for each news article?
    – No Sssweat
    Mar 2, 2016 at 23:04

1 Answer 1


Just a single flag for the rendered page view that displays all articles (i.e., a way to bookmark the "read all news" page.)

ok then doing it the way you were doing it, is the way to go.

$node->nid alone won't return the nid, you need to to use menu_get_object() function


if ($node = menu_get_object()) {
  // Get the nid
  $nid = $node->nid;

print flag_create_link('bookmarks', $nid);



Note 1: If you're using a page view, the above won't work since it cannot fetch an nid since page view's don't have node id's. In order to get it to work, you can create a block view, and then create a node where you insert your block view. Then since the node has a nid, it's able to fetch the node id.

Note 2: You can ignore all the comments below, as they were due to using a page view (see note1)

  • Unfortunately with that I get Notice: Undefined variable: nid in include() (line 35 of /var/www/mysite.dev/public_html/sites/all/themes/mytheme/views-view.tpl.php). I'm assuming that's because menu_get_object() tries to return a nid from a path, when the path is not in fact a node but instead is an on-the-fly rendering of several nodes (news articles, in this case) created by Views. Mar 3, 2016 at 14:29
  • humm.. it should return the path of the page/node you're on. Not what's on the view. Are you using a Page view or a Block view? If you're using a page view, then that explains the error.
    – No Sssweat
    Mar 3, 2016 at 22:29
  • try just using print $nid; to see if you still get the error.
    – No Sssweat
    Mar 3, 2016 at 22:31
  • Yes, it's a page view. I tried <?php print $nid; ?> on my views-view.tpl.php and I get the same error. Mar 4, 2016 at 16:11
  • 1
    Sorry, I forgot this was a page view, which explains why it can't find a nid. In order to get it to work, you would have to create a node of article, basic page or any other content type, and insert your view using a block view.
    – No Sssweat
    Mar 11, 2016 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.