Hello,

I try to add a counter next to my flag link.

I saw that you can display it by using this snippet :

$flag = flag_get_flag('my_flag');
print $flag->get_count($nid);

The problem is that I have to put that code in flag.tpl.php and it's displayed on a node listing (so node teaser view mode).

How can I get the $nid of the node currently processed ? I'm not on the node page so I cannot load the node $nid using (arg(1)) and the $flag array doesn't seems to have any informations on the current processed node.

Thank you for your help

Alex

CommentFileSizeAuthor
#2 2222373-add-missing-tpl-vars.patch1.32 KBpebosi
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Title: Get node id in flag.tpl.php » missing vars in flag.tpl.php documentation
Version: 7.x-3.4 » 7.x-3.x-dev
Component: Flag core » Documentation
Category: Support request » Bug report
Issue tags: +Novice

The Flag TPL surely has a variable for the entity id it's output for. Looking at the preprocessor, looks like it's

  $entity_id = $variables['entity_id'];

BTW it's always a good idea to use devel module to do dpm(get_defined_vars()) in a tpl file to see everything that's there.

Converting this to a bug report so we fix the omissions in the template docs, and tagging as Novice. What's required here is:

- use the devel trick above to get a list of the variables the template has
- check in template_preprocess_flag() to see what they represent
- add the ones that should be there but are missing (we probably don't want things like the CSS class arrays flag_wrapper_classes_array and friends for example)

pebosi’s picture

Assigned: Unassigned » pebosi
Status: Active » Needs review
FileSize
1.32 KB

See attached patch

joachim’s picture

Status: Needs review » Fixed

Committed, with a small tweak for a missing full stop.

Thanks for the patch!

  • Commit 0443fc7 on 7.x-3.x authored by pebosi, committed by joachim:
    Issue #2222373 by pebosi: Fixed missing variables in flag.tpl.php...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.