I have a views block on a node page using a term argument to generate a list of nodes.

How do I generate a flag link for that term that that the views is based on? I would like to put it in the views header or in the a block somewhere.

Thanks.

Comments

tayzlor’s picture

Hi There,
if the page is not a taxonomy term page then you would need to use the flag API to create a flag link for the term.

You can do this using the flag_create_link($flag->name, $term->tid); function.

Here's some more documentation on how you can place a flag link on a page - http://drupal.org/node/295383

ManyNancy’s picture

Do you need to load the term first? This is not working for me.

ManyNancy’s picture

Nevermind, it works well :). (cache problems)

Do you know how to add classes to the link?

Thanks.

ManyNancy’s picture

Status: Active » Fixed
tayzlor’s picture

Status: Fixed » Closed (fixed)

@Minqensan,

there is a flag.tpl.php inside the flag folder which renders the html for the flag link. You can add classes to it here (or in a template preprocess function for the flag.tpl file.

issue fixed so setting this to closed.

amsterdamdrupalnewbie’s picture

How would I get this to work with version 7.x-1.x-dev? I have tried using the following, in a block, and limiting it to taxonomy pages:

print flag_create_link('like', $term->tid);

where 'like' is the machine name of my flag, but it returns an error.