Skip to main content

Template Context

Template context

When editing a forum theme template, we provide variables filled with relevant forum data you may find useful in building a template. For each template, we make available global, page-specific, and loop-only variables. Because we optimize data loading in these variables for a specific context, we will explain each type of variable along with examples to help you use understand and use the data we provide to build a more robust forum template.

Global Variables

Some variables are available globally. Template variables available in this context contain data that is generally loaded by default by any page. This context also includes some variables that have been deemed as useful for access in a global context.

Examples of global variables:

Current User

The current user is always loaded with the page. This data could be used for something like displaying the current user's like count on a fixed bar on the top of the page.

Navigation

Navigation is available globally to allow theme developers to add navigation data anywhere they would like to affect their forums usability.

<!-- A friendly thank you to users who post a lot that can be placed in the header, or sidebar -->
{if $[current_user.posts] > 50}
<span>Thank you very much for using the forum!</span>
{/if}

Page Specific Variables

Many variables are only available in the context of their own page. This is generally because it would be inefficient to load this data on every pageload, but also can be the result of the template variable not having any use outside of the specific page.

Examples of page specific variables:

Conversation

Conversation data is page specific for the conversation list and message list pages. It would only make sense to load conversation variables for these two pages as public pages generally wouldn't need access to private information such as user messages.

Group Powers

Group powers are only accessible when retrieving data for a specific group. This information would only be loaded in specific circumstances, such as when viewing what powers a group possesses.

Loop Only Variables

Some variables are available in many different page contexts, but are only usable within a loop. All of these variables consist of a list of objects. The object's properties may be referenced within the loop using the template variable's name in the same way that you would access other template variable's specific data properties. In many cases, a named variable that would be contextually singular on one page will represent an object list.

Examples of loop only variables:

Post

There are a few examples of post variable lists. One is the global variable, $[recent_posts] which can be used to display the dat of recent posts throughout the forum. Another is $[post_list] which is used when showing a thread. They make use of the loop-only $[post] variable.

<!-- This $[post} variable must be used within a for loop -->
{foreach $[post]}
<span>$[post.message]</span>
{if $[post.created_by] > 15}
<span>This post was not made by one of the original 15 members of the forum</span>
{/if}
{/foreach}

User

When displaying the members list user data is available using the $[user] variable.