Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#2 | 2222373-add-missing-tpl-vars.patch | 1.32 KB | pebosi |
Comments
Comment #1
joachim CreditAttribution: joachim commentedThe Flag TPL surely has a variable for the entity id it's output for. Looking at the preprocessor, looks like it's
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)
Comment #2
pebosi CreditAttribution: pebosi commentedSee attached patch
Comment #3
joachim CreditAttribution: joachim commentedCommitted, with a small tweak for a missing full stop.
Thanks for the patch!