Iain Urquhart

Taxonomy

taxonomy:set_node

Set the current tree and node for all taxonomy tags

{exp:taxonomy:set_node tree_id="1" key="entry_id" val="{entry_id}" var_prefix="this_"}

If you're sick of repeating yourself on a single template with tree_id="x" and entry_id="x" then you'll find this tag useful for making your code a little more DRY.

Example:


This tag accepts all the parameters of the get_node tag, and makes all the same variables available as global variables (with your optional prefix).

Now if you notice on the template above I have a conditional around if this_node_has_children == 'yes'... - that's pretty cool right?

Well yeah, nah, yeah... I suggest you spend some time experimenting as the parsing results might not be as you expect. In this case it works because the dynamic global variable 'this_node_has_children' gets parsed quite late because it's in a conditional - if you just tried to output the variable {this_node_has_children} in this template, it's not going to work. (Yes, head melt time).

What is also very neat is that because the global vars have been set here, any embedded templates will have access to the vars very early. So in an embed, 'this_node_has_children' will be available for you, and you also won't have to set the node or define the tree_id or entry_id again - again as it has been set by the parent template.

I could easily bamboozle the crap out of you trying to document what is possible with this tag, but I'll leave it to you to experiment and maybe share what you've done on the Devot:ee forums :)


If you place this tag several times on the same template you will have unexpected results, it's intended to be placed once per page load.

Want to say 'thank you'?

If you find any of my work useful, feel free to make a donation amount of your choosing via PayPal — or if you like, purchase a copy of Introvert from Devot-EE and you'll get something in return :)

↑ Back to top