Navigation:  Front-End > Templates >

Smarty Template Tips

Print this Topic Previous pageReturn to chapter overviewNext page

Here are a few tips to help get you to customizing your templates like a pro.

 

Print a Field:

In many of your front end templates, if you would like for the value of a field to be present on the page, all you need to do is add the proper variable code to the template.

Example...

Adding the variable code {$location.name} will cause the records 'name' field to be printed.  The variable will be replaced with the location's actual name, such as 'Texas Motorsports, Inc.'.

 

Adding the variable code {$location.user1} will cause the records' 'user1' field to be printed.  The variable will be replaced with the location's actual value in the user1 field, such as 'We're open 24hrs a day'.  (Obviously, you need to implement user fields and have data in the user1 field for anything to print.)


 

If Statements:

If Statements are a great way to test the condition of a variable before you do anything with it.

Example:

Adding the variable code {if $location.address2 neq ''}  <br>{$location.address2} {/if} will only use the break line code and print the value of the 'address2' field if data is present in the address2 field.  If it's blank, nothing will print.

 

Adding the code

{if $location.website neq ''}

<a href="http://{$location.website}">Online Store Now Available!</a>

{else}

<a href="{$location.email}">Contact via Email</a><br>

{/if}

The above code will check to see if the location has data in the website field.  If it does, it will then create a link to the website.  If it does not, it will create a link for email.


 

Print Fields in HTML Format:

All fields are stored in the database in plain text and using standard ASCII format.  And all references of HTML are stored in their ASCII code.  If you have a field you are using html in, you may wish to decode it to html before it gets printed to the screen.

 

Example:

If you have entered HTML into your user1 field...

Adding the variable code

{$location.user1} will print like this:

 

M-F: 8:00am until 5:00pm&lt;br&gt;

&lt;font color=&quot;blue&quot;&gt;Blue Sale on Saturdays&lt;/font&gt;

 

 

If you want the user1 field to print in HTML, then you can use the following variable code alteration:

{$location.user1|html_entity_decode} and the value will print like this:

 

M-F: 8:00am until 5pm

Blue Sale on Saturdays

 

 

Tip: html_entity_decode is a php string function, and you can use any available php function as a variable modifier.  Just add the php function after the variable in the format of |functionname For a list of PHP string functions, visit http://at.php.net/manual/en/ref.strings.php

 

 

 


Page url: http://www.helpandmanual.com/help/index.html?smartytemplatetips.htm