User Tools

Site Tools


How to rework your themes and plugins for FlatPress 1.3 / Smarty 4

This article is still work in progress. It will be subject to further additions and changes.
Found something's incorrect or missing? Feel free to fix it right away, or let us know on the Support Forum.

In older versions (up to 1.2.1), FlatPress comes with version 2.6 of the Smarty template engine.
With FlatPress 1.3 “Andante”, we switched Smarty version 4.

Smarty has changed significantly in between - if you contributed themes or plugins to FlatPress, they might need some changes to work with FlatPress 1.3 and higher.

In this article, we share our experiences and give theme designers and plugin developers hints to successfully rework their themes/plugins to be Smarty 4 compatible. For more details, please consult the Smarty backward compatibility notes.

Themes: Stricter template syntax

Smarty 4 is much less forgiving when it comes to syntax correctness of your template files. In the FlatPress default template files, we had to fix quite a lot of missing attribute quotations: Any attribute value that contains special chars (anything but A-Za-z0-9_) must be quoted now. This concerns file paths, for example.

Okay for Smarty 2 / FlatPress 1.2 Necessary for Smarty 4 / FlatPress 1.3
{include file=shared:errorlist.tpl} {include file=“shared:errorlist.tpl”}
{html_form class=option-set} {html_form class=“option-set”}

Plugins: Changed Smarty API

Tip of the day:
To check each Smarty function call within your plugin code, simply search the code for $smarty->.

Since Smarty 3, the Smarty function name schema is in camelCaseStyle instead of underline_style.

Smarty 2 / FlatPress 1.2 Smarty 4 / FlatPress 1.3
get_template_vars() getTemplateVars()
assign_by_ref() assignByRef()

Also, the different register_…() functions have been combined to registerPlugin($type, …):

Smarty 2 / FlatPress 1.2 Smarty 4 / FlatPress 1.3
register_function(…) registerPlugin('function', …)
register_modifier(…) registerPlugin('modifier', …)

Keep your plugin backward compatible

To make your plugin work with Smarty 2 (FlatPress 1.2) and Smarty 4 (FlatPress 1.3), use the following switch. It determines if a Smarty legacy function is available, thus indicating there's a Smarty 2 running:

$isLegacySmarty = method_exists($smarty, 'register_function');
if ($isLegacySmarty) {
	// code for FlatPress 1.2.x and below
} else {
	// code for FlatPress 1.3 and higher
	$smarty->registerPlugin('modifier', ...);
doc/tips/smarty2to4.txt · Last modified: 2024/03/30 13:24 by arvid

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki