Templates can be pretty powerful. They give you the ability to make your site dynamic, allowing what is displayed to change based upon user interaction, content, and other factors.

Conditional Logic

There may be instances where you want to display a block of content within a template only if certain conditions are met or not met. This is where <r:if> and <r:if_not> come in handy. These tags work by taking two inputs and comparing them using a given operator. If the comparison is true, <r:if> will render its block of content. If you would like to display the block of content when the comparison is false, you would use <r:if_not>.

For example, let's say you want to display a block of content only if the name of the current page is "Special".

<r:if value1="{page:name}" value2="Special" operator="=">
  <strong>This is a special page!!!</strong>
</r:if>

The same thing could be done with a little less typing:

<r:if v1="{page:name}" v2="Special" op="=">
  <strong>This is a special page!!!</strong>
</r:if>

Now suppose, for some crazy reason, we only want to show a piece of content between a very specific time frame each day:

<r:if v1="now" v2="8:00 AM" op=">" type="Date">
  <r:if v1="now" v2="5:00 PM" op="<" type="Date">
     <strong>Displayed between 8 AM and 5 PM daily.</strong>
  </r:if>
</r:if>

Notice that, in the example above, we set type="Date" in the <r:if> tags. This tells the system to treat the values being compared as dates instead of strings, which is the default. If the values should be treated as numbers, you would need to specify type="Number".

Also keep in mind, for the time based example above, that the system may cache page content for a short time, typically around 15 minutes, so you may not see the expected result immediately.

NOTE: Variable names in <r:if> statements must not contain minus (-) characters. Replace minus characters with underscores ( _) or camelCase variable names.

Read the tag documentation for more information.

Loops

If you have a block of content that you need to repeat several times, <r:loop> can be used instead of manually copying & pasting repeatedly. You can loop over a list of items, given by a delimited string, a range of integers, or a set number of iterations. The items to be looped over can come from various places, such as page content, page attributes, custom page attributes, or even the URL.

<r:loop items="foo,bar,baz">
<p>Item Count: <r:item_count /></p>
<r:each>
    <p><r:item /></p>
  </r:each>
</r:loop>

Read the tag documentation for more information.

Last updated on November 20, 2015.

We welcome all questions, feedback and bug reports. If you're having an issue, we usually need the following information:

  • A brief description of the issue
  • A link to the page where you saw the issue
  • Screenshots that illustrate the problem - How do I take a screenshot?

Kindly email CleanSlate@mail.wvu.edu for help or use the form on the request help page.