4. Cookbook

4.1. Injecting variables into all templates (i.e. Global Variables)

As exemplified in the Symfony Cookbook it is possible to make a variable to be accessible to all the templates you use by configuring your app/config/config.yml file:

# app/config/config.yml
    # ...
        ga_tracking: UA-xxxxx-x

Now, the variable ga_tracking is available in all Smarty templates:

<p>Our google tracking code is: {$ga_tracking} </p>

4.2. Trim unnecessary whitespace from HTML markup

This technique can speed up your website by eliminating extra whitespace characters and thus reducing page size. It removes HTML comments (except ConditionalComments) and reduces multiple whitespace to a single space everywhere but <script>, <pre>, <textarea> [1].

To enable this feature add the trimwhitespace output filter in app/config/config.yml:

# app/config/config.yml

# Smarty configuration
            output: [trimwhitespace]