Customised URL/link to a term with tokens in Display Suite
The purpose of this walkthrough is to achieve a link with a tokenised taxonomy URL. This is sometimes required if you have a content type with a taxonomy field of Author or Issue and you want to link to a taxonomy page or view using taxonomy values as contextual filters.
Or for instance, if you want to theme a taxonomy field output on a node page and you are using the taxonomy value as part of a custom URL.
The steps for setting this up have been lifted off an issue queue response by myself to a question found here – http://drupal.org/node/1410034 (acknowledged by filnug (issue reporter) and swentel himself!)
- First create the field output you want to use (or edit the one you have already created), go to Structure > Display Suite > Fields > Add a code field.
- Give the field a label.
- Select the entity type the field will be made available for, select Taxonomy term.
- Where you would have node field code like
<a href="[node:field_fruit]">[node:field_fruit]</a>(field_fruit is a taxonomy field) replace the node field tokens with taxonomy ones, ie
- Select an input format that will provide the cleanest version of the output, ie Filtered or Full HTML but with no news lines added.
- Ensure you have ticked the 'this field uses tokens' checkbox.
- Save the custom field.
- Now set up a new view mode for the taxonomy term, go to Structure > Display Suite > View modes > Add a view mode.
- Give it a name, like [content type] page or something like that, select Taxonomy Term under the entity type that it is available for.
Set the code field for the taxonomy output
- Now head over to the vocabulary display, go to Structure > Taxonomy > [vocabulary] > Manage Display.
- Under the Default view you should see Custom display settings, tick the new one you created and Save.
- Set layout to one column (minimal amount of DS wrap-age).
- You will see the fields available for the display, which should include the code field you created.
- Put that into the content region for the display.
- Set the field display to full reset (or if you want to add a wrapper go ahead).
- Save the view mode display.
Set format for your taxonomy field
- Finally... go to the content type display now, via Structure > [content type] > Manage Display.
- If you have a view mode already set up to use the taxonomy field then in the Format drop down choose the View Mode : [name-of-view-mode].
- Save the view mode.
- The output for the field should now display the output of code field but using the taxonomy values for the token substitutions.
This will provide the output for the taxonomy term as a URL segment and as the text part of the link, but it does mean you will have one div wrapper from DS for the one column layout. Ideally you could add a custom layout that doesn't use any extra formatting, so that you get a nice clean output for the taxonomy field.
If you aren't fussed about an extra div then this should work for you.
The alternative is if the taxonomy term field when referenced via a node token had all the extra attributes available, ie pathauto alias, path, etc. But from hunts around the web and drupal.org that appears to not be available yet. It was available in Drupal 6 via the very useful Taxonomy Token module, fingers crossed we see it in Drupal 7 soon.