[2.0] Smarty3
Posted: Sun Jan 02, 2011 9:48 pm
Smarty 3 is currently still having many point releases to Smarty3. Implement once it has stabilized and maturized more.
Hi!Timbalu wrote:Shall I give it a try?
Is there anything to think of (embedding, configs, wrappers, etc.) before I do so?
Ian
Code: Select all
all $serendipity['smarty']->assign_by_ref() calls have to get changed to $serendipity['smarty']->assignByRef()
all $serendipity['smarty']->register_function(..., ...) calls have to get changed to $serendipity['smarty']->registerPlugin('function', ..., ...)
all $serendipity['smarty']->register_modifier(..., ...) calls have to get changed to $serendipity['smarty']->registerPlugin('modifier', ..., ...)
$serendipity['smarty']->register_prefilter(...) has to get changed to $serendipity['smarty']->registerFilter('pre', ...)
Code: Select all
function &serendipity_smarty_fetch($block, $file, $echo = false) {
global $serendipity;
$output =& $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, ($echo === true && $serendipity['smarty_raw_mode']));
$serendipity['smarty']->assignByRef($block, $output);
return $output;
}
Code: Select all
function &serendipity_smarty_fetch($block, $file, $echo = false) {
global $serendipity;
$output =& $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null);
$serendipity['smarty']->assignByRef($block, $output);
return $output;
}
Code: Select all
class serendipity_smarty extends smarty {
function assign_by_ref() { $this->assignByRef(...) }
...
}
Is it an option to switch to Dwoo since we're likely to move to PHP5 anyway?garvinhicking wrote:Aw man, that sucks.
No, we should not need to, sorry for this mess. These old register methods have their own wrapper and just throw notices. Thats why I changed them to the new writing. I don't think there are much plugins around using these methods (I found staticpage (and bulletproofs config) only). The README says clearly:garvinhicking wrote:Rewriting all plugins and the core is a route we can't really go. I wish, Smarty wouldn't have gone that way, it's a unneccesary BC break.
PHP5 means we need 5.2+. I use the old methods now and despite of being more strict in some places my test scenario is working.However, Smarty 3 works completely different on the inside. Smarty 3 is mostly
backward compatible with Smarty 2, except for the following items:
*) Smarty 3 is PHP 5 only. It will not work with PHP 4.
*) The {php} tag is disabled by default. Enable with $smarty->allow_php_tag=true.
*) Delimiters surrounded by whitespace are no longer treated as Smarty tags.
Therefore, { foo } will not compile as a tag, you must use {foo}. This change
Makes Javascript/CSS easier to work with, eliminating the need for {literal}.
This can be disabled by setting $smarty->auto_literal = false;
*) The Smarty 3 API is a bit different. Many Smarty 2 API calls are deprecated
but still work. You will want to update your calls to Smarty 3 for maximum
efficiency.
Code: Select all
{foreach from=$entries item="entries"}
{foreach from=$entries.entries item="entry"}
Code: Select all
{foreach from=$entries item="xentries"}
{foreach from=$xentries item="xentry"}
{foreach from=$xentry item="entry"}
{if is_array($entry)}
is something for me! Posting the lines to change is easy.or so
Code: Select all
{foreach from=$entries item="sentries"}
{foreach from=$sentries.entries item="entry"}
Code: Select all
Array
(
[date] => 1292256366
[is_sticky] =>
[entries] => Array
(
[0] => Array
(
[id] => 1
Code: Select all
Array
(
[20100908] => Array
(
[date] => 1283952751
[is_sticky] =>
[entries] => Array
(
[0] => Array
(
[id] => 64
Code: Select all
if(strpos($serendipity['smarty']->_version, '2', 1))
// compat Smarty2 only
else
// compat Smarty3 only
Code: Select all
if(strpos($serendipity['smarty']->_version, '2', 1))
$content = $serendipity['smarty']->fetch('file:'. $tfile, null, null, false);
else
$content = $serendipity['smarty']->fetch('file:'. $tfile, null, null, null, false);