User Guide & Reference Manual

Global Plugins

Like global variables, these plugins are available for use in any template. Of course, they aren't the only plugins you can use across your templates - the Smarty Template Engine has lots of built-in plugin functionality, as well.

{custom_field}

Display a form element from a standard custom field data array for one field.

Parameters
Parameter Required? Description
field Required An array for a custom field containing data such as "name", "type", "options", etc. This is automatically generated by Hero.
value No The current value of the field. If no value is passed, we will attempt to retrieve a value from the current POST submission, if available.

Usage (assuming the template has been passed an array of custom fields as $custom_fields):


{foreach $custom_fields as $field}
	<li>
		<label for="field_{$field.name}">{$field.friendly_name}</label>
	</li>
	<li>
		{custom_field field=$field}
	</li>
	{if $field.help}
		<li>
			<div class="help">{$field.help}</div>
		</li>
	{/if}
{/foreach}

Usage (specifying a default value):


{custom_field field=$field value="Predefined Value"}

{money_format}

Format a given value as if it was currency.

Parameters
Parameter Required? Description
value Required The value to format and return as a valid currency figure.

Usage:


This product costs {money_format value=$product.price}.

{paginate}

Generate the HTML for a set of paginating links. These links provide an easy way for users to go forward or back through a series of pages, or click through to a specific page number.

Parameters
Parameter Required? Description
base_url Required The URL upon which paginating query strings will be affixed (e.g., $current_url).
total_rows Required The total number of items in the dataset (e.g., "45" if there are 45 blog posts to paginate).
per_page Required How many items are displayed on each page?
variable Required This is the name of the variable that will be affixed to the "base_url" (e.g., if you specify "page" as the base_url, then "?page=X" will be added to this URL to denote the different pages).

Example (being passed certain variables such as $total_rows dynamically):


{paginate variable="page" base_url=$current_url total_rows=$total_rows per_page="50"}

Will display:


<ul>
	<li>
		<a class="active" href="http://www.example.com/blog?page=1">1</a>
	</li>
	<li>
		<a href="http://www.example.com/blog?page=2">2</a>
	</li>
	<li>
		<a href="http://www.example.com/blog?page=3">3</a>
	</li>
	<li>
		<a href="http://www.example.com/blog?page=2">Next</a>
	</li>
</ul>

{parse_as_template}

Parse the given variable as if it were a Smarty template itself. This is highly useful for when you may be using template tags within published content.

The variable will only be parsed as a template if the plugin auto-detects that it has Smarty variables or tags of some kind (this saves resources).

Example:


// within a content template

<h1>{$title}</h1>

{$body|parse_as_template}

{protected_link}

Protect a file download URL from being shared by using this tag to generate a unique file access URL which validates the member's member group status upon each request.

Parameters
Parameter Required? Description
url Yes The URL to protect from unauthorized access. This may be relative (e.g., "/writeable/uploads/test.pdf") or absolute (e.g., "http://www.example.com/writeable/uploads/test.pdf").
groups Yes An array of member group ID's which can access this resource. If passed a single group (e.g., "4"), this one group alone will have access. You may also pass multiple groups as an array variable, or like "2|5|6".
filename No If you are protecting a download, you can specify the filename of the download. Otherwise, it will be a random alphanumeric string.

Basic usage, within a content template, where there are at least two content fields called file_download and file_size as well as standard access restrictions set in the control panel for this content:


<a href="{protected_link url=$file_download groups=$privileges}">Click here to download the file</a> ({$file_size}).

This would return an encrypted link that would verify the user has the proper privileges every time it is accessed, preventing the user from sharing the link.

We can also pass a filename so the user has the original name of the file:


<a href="{protected_link url=$file_download groups=$privileges filename="report"}">Click here to download the file</a> ({$file_size}).

{restricted}

Display or hide certain content in a template based on the user's being in (or not being in) specified member groups.

Parameters
Parameter Required? Description
in_group No The user must be in (at least one of) this/these group(s) to see the content. Can be a single group ID like "4", a combination of groups like "4|5|3", or an array of group ID's such as that passed by standard content like "{$article.privileges}".
not_in_group No The user must not be (in any of) this/these group(s) to see the content. Can be a single group ID like "4", a combination of groups like "4|5|3", or an array of group ID's such as that passed by standard content like "{$article.privileges}".

If the user is in the in_group and not in the not_in_group, the content between the tags is parsed. Both tags are optional. Furthermore, if you want to check either the in_group or not_in_group status of the user against multiple member group ID's, you can pass a string like "1|2" (each member group ID is separated by a pipe).

Note that, while most of the examples below show the parameters passed as integers or pipe-delimited strings, you can also pass arrays such as the standard {$privileges} array used in many Hero modules.

Basic usage:


{restricted in_group="3"}
Only users in group #3 can see this.
{/restricted}

Check against multiple member groups:


{restricted in_group="1|5"}
Users in either or both groups #1 and #5 can see this.
{/restricted}

User must be in a group but not in another group:


{restricted in_group="5" not_in_group="3"}
Content is only shown if user is in group #5 but no in group #3.
{/restricted}

Example with a content privileges array:


{restricted in_group=$privileges}
	You are in this group.  I'll show you the full article:
	
	{$title}
	Published on {$date}.
	
	{$body}
{/restricted}

{restricted not_in_group=$privileges}
	You are not in the group.  Sorry.
{/restricted}

{shorten}

Shorten a string of text to a specific length and attach "..." to the end of it.

Parameters
Parameter Required? Description
string Required The text to be shortened, either as a variable (e.g., {$article.body}) or a text string.
length Required The maximum character count length for the string. If the string is not greater than this length, it will be returned unaltered. Otherwise, it will be returned shortened with "..." appended to it.

Usage:


Print a summary of the article body: {shorten length="250" string=$body}

{setting}

Retrieve a site configuration or setting value. All standard Hero settings viewable in the control panel at Configuration > Settings. Furthermore, all configuration variables defined in /app/config (standard CodeIgniter variables) are also available.

Parameters
Parameter Required? Description
name No The name of the setting to retrieve.

Usage - site title:


{setting name="site_title}

Returns to template:


Your site title

Another example - site base URL:


{setting name="base_url"}

Returns to template:


http://www.yourbaseurl.com OR https://www.yourbaseurl.com, depending on SSL status

Final example - the site's currency symbol:


This product costs {setting name="currency_symbol"}{$product.price}

Returns to template:


This product costs $45.00

{theme_url}

Retrieve an absolute URL within your active theme's folder with a relative URL path. Will use HTTPS if necessary.

Parameters
Parameter Required? Description
path Required The relative path within your theme folder (e.g., "js/universal.js").

Usage:


{theme_url path="images/theme_header.gif"}

Returns to template:


http://www.yourdomain.com/themes/yourtheme/images/theme_header.gif

{thumbnail}

Create a thumbnail of an image and return the URL to this cached thumbnail image.

Parameters
Parameter Required? Description
path Required The full server path to the image (e.g., "/home/webuser/public_html/writeable/images/test.jpg").
height Required The maximum height of the image thumbnail.
width Required The maximum width of the image thumbnail.

This function actually wraps the image_thumb helper function. It works with your Hero default image processing settings configured in config.php.

This function keeps the proportion of the image, using the "height" and "width" parameters as the maximums for the returned thumbnail. So, if you resize an image with 100x100 width/height, you may get an image that is 100x80 or 95x100, etc.

Usage:


{* This would occur within a product page *}
<img src="{thumbnail path=$image.path width="80" height="80"}" alt="Image Thumbnail" />

Returns to template:


<img src="http://www.example.com/writeable/image_thumbs/fsdf24r02j8paja3894dfkf8fj2a2.jpg" alt="Image Thumbnail" />

{url}

Retrieve an absolute URL relative to your site's base URL. Will use HTTPS if necessary.

Parameters
Parameter Required? Description
path Required The relative path of the link.

Usage:


{url path="my_page.html"}

Returns to template:


http://www.yourdomain.com/my_page.html

{xss_clean}

Cleanse a string of all XSS maliciousness for displaying in a template.

Parameters
Parameter Required? Description
string Required The suspicious string.

Usage:


This is from a GET query parameter, so we should cleanse it: {xss_clean string=$smarty.get.test_param}

Returns to template:


This is from a GET query parameter, so we should cleanse it: Parameter value