PK $h:BÈM¢sd@ d@ smartybundle-v1.1.0/intro.html
This bundle was created to support Smarty in Symfony2, providing an alternative to the Twig template engine natively supported.
Note
An effort was made to provide, where possible, the same user configuration and extensions available for the Twig bundle. This is to allow easy switching between the two bundles (at least I hope so!).
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic. This implies that PHP code is application logic, and is separated from the presentation.
Some of Smarty’s features: [1]
See the Smarty3 Manual for other features and information on it’s syntax, configuration and installation.
[1] | http://www.smarty.net/docs/en/what.is.smarty.tpl |
This bundle is licensed under the LGPL-3 License. See the LICENSE file for details.
This bundle is licensed under the LGPL-3 License. See the LICENSE file for details.
A big thanks to all SmartyBundle contributors and everyone who helped along the way.
Author: | VÃtor Brandão (noisebleed@noiselabs.org) |
---|---|
Version: | 1.1.0-DEV |
Date: | January 26, 2013 |
Note
A lot of the content found in this documentation was “borrowed” from Smarty and Symfony2 documentation pages and websites. Credits goes to Smarty and Symfony authors and contributors.
When contributing to SmartyBundle you should follow the standards defined in the PSR-0, PSR-1 and PSR-2. documents.
Here’s a short example:
<?php
/**
* This file is part of NoiseLabs-SmartyBundle
*
* NoiseLabs-SmartyBundle is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* NoiseLabs-SmartyBundle is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with NoiseLabs-SmartyBundle; if not, see
* <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2011-2012 VÃtor Brandão
*
* @category NoiseLabs
* @package SmartyBundle
* @author VÃtor Brandão <noisebleed@noiselabs.org>
* @copyright (C) 2011-2012 VÃtor Brandão <noisebleed@noiselabs.org>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL-3
* @link http://www.noiselabs.org
*/
namespace NoiseLabs\Bundle\SmartyBundle;
/**
* This class provides X.
*
* @author John Doe <john@example.com>
*/
class FooBar
{
const SOME_CONST = 42;
private $fooBar;
/**
* @param string $dummy Some argument description
*/
public function __construct($dummy)
{
$this->fooBar = $this->transformText($dummy);
}
/**
* @param string $dummy Some argument description
* @return string|null Transformed input
*/
private function transformText($dummy, $options = array())
{
$mergedOptions = array_merge($options, array(
'some_default' => 'values',
));
if (true === $dummy) {
return;
}
if ('string' === $dummy) {
if ('values' === $mergedOptions['some_default']) {
$dummy = substr($dummy, 0, 5);
} else {
$dummy = ucwords($dummy);
}
}
return $dummy;
}
}
VÃtor Brandão - noisebleed@noiselabs.org ~ twitter.com/noiselabs ~ blog.noiselabs.org
See also the list of contributors who participated in this project.
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
smarty:
# ...
globals:
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>
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
smarty:
options:
autoload_filters:
output: [trimwhitespace]
[1] | http://stackoverflow.com/a/9207456/545442 |
The example below uses YAML format. Please adapt the example if using XML or PHP.
app/config/config.yml:
smarty:
options:
# See http://www.smarty.net/docs/en/api.variables.tpl
allow_php_templates:
allow_php_templates:
auto_literal:
autoload_filters:
cache_dir: %kernel.cache_dir%/smarty/cache
cache_id:
cache_lifetime:
cache_locking:
cache_modified_check:
caching:
caching_type:
compile_check:
compile_dir: %kernel.cache_dir%/smarty/templates_c
compile_id:
compile_locking:
compiler_class:
config_booleanize:
config_dir: %kernel.root_dir%/config/smarty
config_overwrite:
config_read_hidden:
debug_tpl:
debugging:
debugging_ctrl:
default_config_type:
default_modifiers:
default_resource_type: file
default_config_handler_func:
default_template_handler_func:
direct_access_security:
error_reporting:
escape_html:
force_cache:
force_compile:
locking_timeout:
merge_compiled_includes:
php_handling:
plugins_dir:
smarty_debug_id:
template_dir: %kernel.root_dir%/Resources/views
trim_whitespace : false
trusted_dir:
use_include_path: false
use_sub_dirs: true
globals:
# Examples:
foo: "@bar"
pi: 3.14