Using conditionals in module layouts to list Global Tags by headings

May 26, 2014 3:43 pm

Global Tags are useful for assigning values in custom fields used for classification, such as a field for 'Skills' listed on Membership profile detail pages, or any field used for classification of Tags for items in a custom directory. This article shows you how to use conditionals properly in your Module Layouts so that each classification field functions as a heading that will only appear if there are one or more Tags assigned in the corresponding field.

In simplest terms, this is what we wish to accomplish: "If there are Tags, display a Tag heading and list the Tags, or else don't show anything."

For an example, let's assume that there are three custom fields used for classifying and displaying Tags on a member's profile page, which uses the Membership Module Layout labeled "[Detail]", and these will be used as the headings:

  • Skills
  • Honors
  • Associations

Each of the above classification fields has an associated Tag Module Layout:

  • layout.tags_skills
  • layout.tags_honors
  • layout.tags_associations

Continuing with the Membership example, in the Membership [Detail] module layout, we insert each of the above Tag layouts one after the other, like so:


Then, we simply go into each of the relevant Tags module layouts themselves, and in the 'Body' section of the layout, write in a conditional similar to the following:

<if [[count]]>

Ensure that the 'Item' section of each of the Tags module layouts displays the following (which should be present by default):

<if ([[last_tag_#]] != [[tag_#]] && [[max_depth]] > 1)><li><ol></if><li>[[tag]]</li><if ([[leaf]] == 1 && [[max_depth]] > 1)></ol></li></if>

Repeat for each of the Tag layouts, and each Tag heading along with existing Tags will only display if there are Tags specified for it,