Functions

Smarty Functions

This section outlines all the Vanilla-specific Smarty functions made available for use in your Smarty templates.

You are also able to use the built-in Smarty functions in your template.

Function: {debug}

Opens up the Smarty debug console in a popup window. This will show you all of the data available to the smarty template. This data matches the data attribute on the page’s controller.

Additional data can be easily added by using the setData() method. See the themehooks documentation for detail.

Usage

{debug}

Function: {asset}

Usage

{asset name="string" id="string" tag="string" class="string"}

Renders an asset from the controller.

Assets in Vanilla are containers for different sets of content. The content of each of these asset containers is variable depending on the page. The content of each asset is not currently configurable via the template.

Vanilla’s asset names are Head, Foot, Content and Panel. Your template will need to contain the Head, Foot and Content assets. The Panel asset is optional, but you’ll likely want to at least include it in the Profile, EditProfile and Conversation sections as it has important functionality in those sections that are not included in the Content asset.

Parameters

Parameter Type Default Description
name string none The name of the asset
tag string $name The id of the tag if different than the name
id string none The type of tag to wrap the asset in
class string none The class to add to the asset wrapper

Function: {breadcrumbs}

Usage

{breadcrumbs homelink="string" hidelast=boolean}

Render a breadcrumb trail for the user based on the page they are on.

Parameters

Parameter Type Default Description
homelink string Home Title of the first link in the breadcrumbs
homeurl string / URL of the first link in the breadcrumbs
hidelast boolean false Whether or not to hide the currently active (last) crumb

Function: {custom_menu}

Usage

{custom_menu format="string" wrap="string"}

A bucket for addon menu items. Adds links depending on which addons are enabled.

Parameters

Parameter Type Default Description
format string none Custom format to use when wrapping links. Available template variables are %url, %class, and %text
wrap string li Element to wrap around each link in the menu

Function: {event}

Usage

{event name="string"}

Fire an event with the specified name. Learn more about events in Vanilla.

Parameters

Parameter Type Default Description
name string none Name of the event to fire

Function: {homepage_title}

Usage

{homepage_title}

Writes the site title to the page. You can change the site title from the ‘Banner’ settings page in the dashboard.

Parameters

This tag does not take any parameters.

Function: {t}

Usage

{t c="string" d="string"}

Output a translatable string with an optional default.

Parameters

Parameter Type Default Description
c string none The string to output or a string short-name
d string $c Default translation. Good idea to set when using short-names

Function: {include_file}

Usage

{include_file name="string"}

Inserts the contents the specified file into the template. The file must be in the same directory as the Smarty template file. Especially useful for inserting html headers or footers into a Smarty template.

Parameters

Parameter Type Default Description
name string none The name of the file to include

Usage

{link path="string" text="string" notag=boolean format="string" withdomain=boolean}

Takes a route and prepends the web root (expects /controller/action/params as path).

Parameters

Parameter Type Default Description
path string none The relative path for the url. There are some special paths that can be used to return ‘intelligent’ links
text string none HTML text to be put inside an anchor. If this value is set then an HTML <a></a> is returned rather than just a url
notag boolean false Whether or not the output should be wrapped in a tag or just be a URL
format string none Custom format to use when wrapping links. Available template variables are %url, %class, and %text
withdomain boolean false Whether or not to prepend the base (http://your-forums.com/) URL to the outputted link

We’ve created dedicated Smarty functions for a number of links to Vanilla pages that make it easier to build your forum’s navigation.

Usage

Here’s the basic syntax, where * is the link type.

{*_link wrap="string" text="string" format="string"}

They take all of the same parameters as a {link} but have the path and string prefilled. These include

Parameters

Parameter Type Default Description
path string none The relative path for the url. There are some special paths that can be used to return ‘intelligent’ links
text string none HTML text to be put inside an anchor. If this value is set then an HTML <a></a> is returned rather than just a url
notag boolean false Whether or not the output should be wrapped in a tag or just be a URL
format string none Custom format to use when wrapping links. Available template variables are %url, %class, and %text
withdomain boolean false Whether or not to prepend the base (http://your-forums.com/) URL to the outputted link

Link to the My Bookmarks page.

Link to the categories page.

Link to the current category page.

Link to the dashboard.

Link to the discussions page.

Link to the drafts page.

Link to the recent activity page.

Link to the forum root page.

Link to the home page.

Link to the inbox.

Link to the My Discussions page.

Link for showing the desktop version of the site.

Link to the session’s user profile that displays as the user’s avatar.

Link to session’s user profile. The link text is the username. Includes a notification count.

If there is a valid session, this outputs a signout link, otherwise a signin link.

If there is a valid session, this outputs a signout link, otherwise a signin link.

Link to session’s user profile. The link text is this username. Does not include a notification count.

Usage

{logo}
{mobile_logo}

Writes the site logo to the page. You can change the site logo from the ‘Banner’ settings page in the dashboard.

Parameters

These tags does not take any parameters.

Function: {module}

Usage

{module name="string" ... }

This is a super handy little function that renders any module in Vanilla. It instantiates the specified module class, sets the properties specified in the function’s parameters and calls the toString() function of the module.

The available parameters differ depending on module itself and the available modules depend on which addons are enabled. If a module is contained in an addon, the addon must be enabled in order for the module to render (a common gotcha).

There are many modules available in Vanilla and in its addons. They can be found in the modules directory of an application or addon. Learn more about modules.

Parameters

Parameter Type Default Description
name string none The name of the asset
tag string $name The id of the tag if different than the name
id string none The type of tag to wrap the asset in
class string none The class to add to the asset wrapper

You can set any property of a module by specifying it as a parameter as long as that property has a setter method or has a visibility of public.

Example

Here’s an example of a tag that renders the Promoted Content Module, a module that can filter discussions based on role, rank, score, category, or the promoted reaction:

{module name="PromotedContentModule" Selector="role" Selection="Developer,Administrator" Limit="12" Group="3"}

Block: {permission}

Usage

{permission require="string"}
    Foo
{/permission}

Only output content if the current user has the specified permission.

Parameters

Parameter Type Default Description
require string none The permission to check / require

Function: {pocket}

Usage

{pocket name="string"}

Writes a pocket to the page. Pockets placed in the template in this way should have their location set to ‘custom’. You can edit this setting from the ‘Pockets’ settings page in the dashboard.

Parameters

Parameter Type Default Description
name string none The name of the pocket

Usage

{searchbox placeholder="string"}

Writes the search box to the page.

Parameters

Parameter Type Default Description
placeholder string Search Optional input box placeholder text

Function: {searchbox_advanced}

Usage

{searchbox_advanced}

Writes an AdvancedSearchModule to the page. This functionality is only the available to the Vanilla Cloud customers with the AdvancedSearch plugin enabled. More details about advanced search can be found in the help documentation.

The advanced searchbox smarty tag does not currently offer a placeholder attribute. It’s placeholder value can be changed by editing the locale key SearchBoxPlaceHolder.

  • Available in Vanilla 2.6

This tag is added by the Hero Image plugin. It returns the url for the hero image of the current page.

Usage

This function is easiest used inside of an img tag or an inline background-image style. These examples will likely require additional styles to be formatted properly.

<img src="{hero_image_alt}" alt="Hero Image" />

<!-- Or as an image -->
<div style="background-image(url('{hero_image_alt}'))"></div>

Function: {text}

Usage

{text code="string" default="string"}

Returns the custom text from a theme’s options page. Learn more about how to configure your theme options.

Parameters

Parameter Type Default Description
code string none The text code set in the theme’s information array
default string none The default text if the user hasn’t overridden

Cloud Hosting

We believe that online communities should be intuitive, engaging and true to your brand. Vanilla allows you to create a customized community that rewards positive participation, automatically curates content and lets members drive moderation.

Learn More …