a wee weblog, since 2006

Custom Fields

Taxonomy 1.1 sees the introduction of custom fields for nodes within Taxonomy Trees. This means that trees can house much more than just a Label, Template Select and URL Override... You're now able to add custom css classes, title attributes, 'open in new window' checkbox, whatever you need :)

Fieldtypes available are Text Input, Textarea, and Checkbox. Checkbox values when checked, are returned as '1'.

Usage Example

Here's what the stock Edit Node interface looks like, without any custom fields.

standard_edit_node
standard_edit_node

Lets say I want my publisher to be able to add a 'Title' attribute to each link, and as a developer, I wouldn't mind being able to attach an additional class to each link too. My tree also has a few external links and my client is demanding I add target="_blank" to those too. Sigh.

Simply visit the tree properties page and add some new custom fields like so:

advanced_settings
advanced_settings

Now when we return to the edit node interface, we'll see our shiny new custom fields:

advanced_edit_node
advanced_edit_node

AND, there's more... Custom fields can also be output to the Fieldtype, so publishers have access to your selected custom fields, right from the publish page :)

publish_node
publish_node

Code Example

So here's a stock standard Taxonomy nav tag

{exp:taxonomy:nav tree_id="1" entry_id="{entry_id}"}
    <a href="{node_url}">{node_title}</a>
{/exp:taxonomy:nav}

With the use case of above, here's how we'd get it working

{exp:taxonomy:nav tree_id="1" entry_id="{entry_id}"}
    <a href="{node_url}"
    	{if target_blank} target="_blank"{/if}
    	{if title_attribute} title="{title_attribute}"{/if}
    	{if css_class} class="{css_class}"{/if}>{node_title}</a>
{/exp:taxonomy:nav}

Some important things to consider

You've got full control over variable names so it's probably best you give your custom fields a prefix so they don't conflict with any system variables, or other custom fields you may use. Use common sense.

Changing a field shortname will not update nodes with values already set, so choose your field short names wisely :)

As captured 12 January 2011 · The archived original