PageRoost 101: Smarty

Posted by Geoff Oliver on November 9, 2015

In this post I will explain what Smarty is, how it's used in PageRoost, and what you can do with it. It's easy to use, but a basic understanding of markup and simple programming concepts like "if" statements is helpful. If you're comfortable with that, let's dive in!

We'll start with a brief explanation of Smarty. Smarty is "a template engine for PHP." That probably doesn't mean much to you, and it shouldn't. Don't worry about it. All you need to know is that, it's more cool stuff that you can do with PageRoost.

PageRoost 101: Smarty in PageRoost


How Does PageRoost Use Smarty?

PageRoost uses Smarty to let you enter snippets of code called PageRoost Variables into your site. You can mix those variables with Smarty functions and get some really awesome results.

Smarty code and PageRoost Variables are always surrounded by {{ and }} characters. This tells PageRoost where the "special stuff" starts and ends so it can work it's magic.


Smarty On Pages

This bit of code below takes the "Start Publishing" date of a page - which is a Unix timestamp localized to your site's "Timezone" setting - and runs it through the "date_format" smarty modifier to output a nice date.

{{$Page.publish_start_timestamp|date_format:"%B %e, %Y"}}

The example above will produce output like this...

May 20, 2016

And remember, you can use this just about anywhere! In your content fields, head and foot code, page titles, templates, form responses, surrounding HTML content for templates, collections, blocks and forms -- on and on. There's no Smarty stuff available in your stylesheets, but you do have access to LESS in them, and that can do some pretty great stuff, too. And don't worry, we'll have a post up soon where we'll show you around LESS and how to use it in PageRoost.


Smarty In Email

You can even use PageRoost Variables and Smarty in email auto responses! The example below illustrates a few concepts: Using the visitor's "First Name" to display a personalized greeting; using the name of the form submitted; customizing a part of the response based on how the recipient completed the form; and then by using the "Site Name" setting value! If you've made it this far, you should understand what's going on below.

Hi {{$Visitor.first_name}},

Thank you for taking the time to fill out our {{$Form.name}} form today. You should expect to hear from us within the next 24 hours.

{{if $Visitor.i_am_a eq "Company"}}
If you are interested in wholesaler information, please contact us by phone at 939-444-1425.
{{/if}}

Thank you,
{{$Setting.site.name}}

That's pretty friggin' awesome, right?!


And That's It!

Well, that's definitely not "it." There's so much you can do with Smarty and PageRoost Variables, definitely more than could - or should - be covered in one blog post. The rest is up to your imagination! Learn about all the PageRoost Variables, get more info on Smarty over at their website, and start having fun!