The trim_blocks option has been removed as the rendered output depends on the value of this option.
This is not a problem for HTML output, but it's a big one if you want to output
plain text for instance.
The behavior now is the same as if the trim_blocks option is set to true. It mimicks
the behavior of PHP tags.
(the old behavior is still possible by adding the "only" keyword)
* Moved Exceptions to Twig_Error_* (Twig_SyntaxError/Twig_RuntimeError are now Twig_Error_Syntax/Twig_Error_Runtime)
+ * removed trim_blocks option
* added support for is*() methods for attributes (foo.bar now looks for foo->getBar() or foo->isBar())
* changed all exceptions to extend Twig_Error
* fixed unary expressions ({{ not(1 or 0) }})
Whitespace Control
------------------
-In the default configuration whitespace is not further modified by the
-template engine, so each whitespace (spaces, tabs, newlines etc.) is returned
-unchanged. If the application configures Twig to `trim_blocks` the first
-newline after a template tag is removed automatically (like in PHP).
+The first newline after a template tag is removed automatically (like in PHP.)
+Whitespace is not further modified by the template engine, so each whitespace
+(spaces, tabs, newlines etc.) is returned unchanged.
Escaping
--------
method that you can use to display the generated nodes (default to
`false`).
- * `trim_blocks`: Mimicks the behavior of PHP by removing the newline that
- follows instructions if present (default to `false`).
-
* `charset`: The charset used by the templates (default to `utf-8`).
* `base_template_class`: The base template class to use for generated
protected $charset;
protected $loader;
- protected $trimBlocks;
protected $debug;
protected $autoReload;
protected $cache;
* method that you can use to display the generated nodes (default to
* false).
*
- * * trim_blocks: Mimicks the behavior of PHP by removing the newline that
- * follows instructions if present (default to false).
- *
* * charset: The charset used by the templates (default to utf-8).
*
* * base_template_class: The base template class to use for generated
$this->setCompiler(null !== $compiler ? $compiler : new Twig_Compiler());
$this->debug = isset($options['debug']) ? (bool) $options['debug'] : false;
- $this->trimBlocks = isset($options['trim_blocks']) ? (bool) $options['trim_blocks'] : false;
$this->charset = isset($options['charset']) ? $options['charset'] : 'UTF-8';
$this->baseTemplateClass = isset($options['base_template_class']) ? $options['base_template_class'] : 'Twig_Template';
$this->autoReload = isset($options['auto_reload']) ? (bool) $options['auto_reload'] : $this->debug;
return $this->getCache() ? $this->getCache().'/'.$this->getTemplateClass($name).'.php' : false;
}
- public function getTrimBlocks()
- {
- return $this->trimBlocks;
- }
-
- public function setTrimBlocks($bool)
- {
- $this->trimBlocks = (bool) $bool;
- }
-
/**
* Gets the template class associated with the given string.
*
mb_internal_encoding($mbEncoding);
}
- return new Twig_TokenStream($tokens, $this->filename, $this->env->getTrimBlocks());
+ return new Twig_TokenStream($tokens, $this->filename);
}
public function setEnvironment(Twig_Environment $env)
protected $eof;
protected $current;
protected $filename;
- protected $trimBlocks;
- public function __construct(array $tokens, $filename, $trimBlocks = true)
+ public function __construct(array $tokens, $filename)
{
$this->pushed = array();
$this->originalTokens = $tokens;
$this->tokens = $tokens;
$this->filename = $filename;
- $this->trimBlocks = $trimBlocks;
$this->next();
}
throw new Twig_Error_Syntax('Unexpected end of template', -1);
}
- // trim blocks
- if ($this->trimBlocks &&
- $this->current &&
+ // mimicks the behavior of PHP by removing the newline that follows instructions if present
+ if ($this->current &&
Twig_Token::BLOCK_END_TYPE === $this->current->getType() &&
Twig_Token::TEXT_TYPE === $token->getType() &&
$token->getValue() &&