Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Related tags

Templating php smarty
Overview

Smarty 3 template engine

smarty.net

Build Status

Documentation

For documentation see www.smarty.net/docs/en/

Requirements

Smarty can be run with PHP 5.2 to PHP 7.4.

Distribution repository

Smarty 3.1.28 introduces run time template inheritance

Read the NEW_FEATURES and INHERITANCE_RELEASE_NOTES file for recent extensions to Smarty 3.1 functionality

Smarty versions 3.1.11 or later are now on github and can be installed with Composer.

The "smarty/smarty" package will start at libs/.... subfolder.

To get the latest stable version of Smarty 3.1 use:

"require": {
    "smarty/smarty": "~3.1"
}

in your composer.json file.

To get the trunk version use:

"require": {
    "smarty/smarty": "[email protected]"
}

For a specific version use something like:

"require": {
    "smarty/smarty": "3.1.19"
}

PHPUnit test can be installed by corresponding composer entries like:

"require": {
    "smarty/smarty-phpunit": "3.1.19"
}

Similar applies for the lexer/parser generator.

"require": {
    "smarty/smarty-lexer": "3.1.19"
}

Or you could use:

"require": {
    "smarty/smarty-dev": "3.1.19"
}

Which is a wrapper to install all 3 packages.

Composer can also be used for Smarty2 versions 2.6.24 to 2.6.30.

Issues
  • Fixed PHP 8 modifier

    Fixed PHP 8 modifier "default"

    PHP 8 has deprecated for "@". But modifier "default" is not compatible.

    plugins/modifiercompiler.default.php // $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; $output = '(($tmp = ' . $output . ' ?? null)===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; // edit by 2020.12.1 -- fixed PHP 8

    opened by juvenrui 46
  • Smarty is dead? alternative engine to migrate to

    Smarty is dead? alternative engine to migrate to

    I see that Smarty hasn't had any updates in 2019, is it dead?

    If yes, then maybe someone could post an alternative php templating engine, so we can start migrating.

    Thank you.

    opened by ghost 35
  • Regression in 3.1.28 - extendsall resource type before template file name doesn't work

    Regression in 3.1.28 - extendsall resource type before template file name doesn't work

    When we use

    {include file="extendsall:template.html"}
    

    in our template, extendsall is not supported at all in 3.1.28. File which defines extendsall resource type is original resource.extendsall.php file from tgz package (demos/plugins/resource_extendsall.php) and is placed in /path/to/application/plugins directory added to plugin dirs by the following code:

    $smarty->addPluginsDir('/path/to/application/plugins');
    

    In 3.1.27 workaround with prefilter replacing {include file="template.html"} by {include file="extendsall:template.html"} was a solution.

    opened by chilek 34
  • smarty should be PSR-0 compatible for autoloading

    smarty should be PSR-0 compatible for autoloading

    enhancement 
    opened by ipranjal 26
  • [Discussion] Raising minimal supported PHP version

    [Discussion] Raising minimal supported PHP version

    This is not the first time such question is raised, but until now it was more in the spirit of "if we raise Smarty, version, then…".

    Now, I'd like to raise the reverse question. Should we actually KEEP supporting PHP5(for now), and for the future, which PHP versions we're supporting and how do we deal with version upgrades?

    Personal opinion following

    As I see it right now, this is no longer a question of "which of PHP5 versions we support?" We can't keep support for 5.6 if we plan to have consistent error handling.

    Here's a list of features I see relevant for Smarty as a project:

    For 7.0:

    For 7.1:

    For 7.4:

    There's a few things in 7.2 and 7.3 that can be considered QoL at best, but nothing I can call a major improvements or life-changer.

    Given an increasing pressure from supporting disparate syntactic constructs between different PHP versions, the list of relevant features and consulting the list of supported PHP versions, I think it would be reasonable to leave Smarty 3.1 targeting PHP=^5.3.6 || ^7.0 (which would be a version bump from current 5.2, but will still probably work with 5.1+) and start a new Smarty version branch (3.2?) targeting PHP=^7.1 || ^8.0 with maintained backward compatibility on template level.

    The choice of version 5.3.6 is made because PHP up to this specific version received fixes to several facilities that I see important for consistent coding practices.

    In addition, I think it may be worthwhile to start deprecation process for legacy Smarty2 constructs while we're still in compatibility mode.

    opened by AnrDaemon 25
  • "extends"'s inheritance chain of templates with the same name

    Hello,

    I assume the following scenario: I have many template directories, when each contains template.html file. Let's assume these directories have names: directory1, directory2, directory3. Then we add all these directories using Smarty::addTemplateDir() method in exact above order to template directories list. I'd like to be able to create templates as below:

    1. template.html from directory3: {block name="contents"}This is {/block}
    2. template.html from directory2: {extends file="template.html"} {block name="contents"}{$smarty.block.parent}the {/block}
    3. template.html from directory1: {extends file="template.html"} {block name="contents"}{$smarty.block.parent}test.{/block}

    I'd like to get as the result the following text: This is the test.

    Now Smarty triggers error in such scenario, because of recursive template loading. It could detect that a given directory has been used as template directory for template.html file already and continue searching for template.html file from next template directory in directory chain. It would allow to create dynamically modified templates with simple usage from php code: $smarty->display('template.html'); This code could be used by something like application plugins.

    Maybe you have another solution for described scenario?

    Bests, Tomasz

    opened by chilek 24
  • Smarty is not compatible with PHP 8.0

    Smarty is not compatible with PHP 8.0

    https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING

    For example, this patch causes a fatal error

    diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl
    index 1fbb6d3..291c3fa 100644
    --- a/demo/templates/index.tpl
    +++ b/demo/templates/index.tpl
    @@ -1,6 +1,10 @@
     {config_load file="test.conf" section="setup"}
     {include file="header.tpl" title=foo}
     
    +
    +{if $smarty.const.TEST}
    +{$smarty.const.TEST}
    +{/if}
     <PRE>
     
     {* bold and title are read from the config file *}
    
    

    Fatal error: Uncaught Error: Undefined constant "TEST" in public_html/smarty/demo/templates_c/234d0264d74c0efb651cf2c28d8975810c02182d_0.file.index.tpl.cache.php:35

    Stack trace:
    #0 public_html/smarty/demo/templates_c/234d0264d74c0efb651cf2c28d8975810c02182d_0.file.index.tpl.cache.php(35): constant('TEST')
    #1 public_html/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_5f32594c42fb41_62206325(Object(Smarty_Internal_Template))
    #2 public_html/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base-&gt;getRenderedTemplateCode(Object(Smarty_Internal_Template))
    #3 public_html/smarty/libs/sysplugins/smarty_internal_runtime_updatecache.php(38): Smarty_Template_Compiled-&gt;render(Object(Smarty_Internal_Template))
    #4 public_html/smarty/libs/sysplugins/smarty_template_cached.php(143): Smarty_Internal_Runtime_UpdateCache-&gt;updateCache(Object(Smarty_Template_Cached), Object(Smarty_Internal_Template), f#5 public_html/smarty/libs/sysplugins/smarty_internal_template.php(211): Smarty_Template_Cached-&gt;render(Object(Smarty_Internal_Template), false)
    #6 public_html/smarty/libs/sysplugins/smarty_internal_templatebase.php(232): Smarty_Internal_Template-&gt;render(false, 1)
    #7 public_html/smarty/libs/sysplugins/smarty_internal_templatebase.php(134): Smarty_Internal_TemplateBase-&gt;_execute(Object(Smarty_Internal_Template), NULL, NULL, NULL, 1)
    #8 public_html/smarty/demo/index.php(36): Smarty_Internal_TemplateBase-&gt;display('index.tpl')
    #9 {main}
    

    due to https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING

    The code like this should not be used

    <?php if (@constant('TEST')) {
    echo @constant('TEST');?>
    
    <?php }?>
    
    opened by ildar-aim 19
  • Use Composer autoloader instead of Smarty_Autoloader

    Use Composer autoloader instead of Smarty_Autoloader

    All you have to do is change composer.json, which won't make Composer autoload bootstrap.php anymore, but make a classmap instead.

    opened by rudiedirkx 16
  • Fatal error: Cannot unset string offsets in vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_block.php on line 337

    Fatal error: Cannot unset string offsets in vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_block.php on line 337

    smarty v.3.1.24

    Stack trace:

    10  87.0320 22877960    Smarty->fetch( string(17), null, null, null, bool, bool, bool ) .../ViewRenderer.php:84
    11  87.0320 22882448    Smarty_Internal_Template->render( bool, bool, bool )    .../Smarty.class.php:824
    12  87.0380 22909816    Smarty_Template_Compiled->render( object(Smarty_Internal_Template)[1804] )  .../smarty_internal_template.php:246
    13  87.0380 22910424    Smarty_Template_Compiled->process( object(Smarty_Internal_Template)[1804] ) .../smarty_template_compiled.php:199
    14  87.0380 22910768    Smarty_Template_Compiled->compileTemplateSource( object(Smarty_Internal_Template)[1804] )   .../smarty_template_compiled.php:152
    15  87.0415 22958584    Smarty_Internal_TemplateCompilerBase->compileTemplate( object(Smarty_Internal_Template)[1804], ???, ??? )   .../smarty_template_compiled.php:226
    16  87.0434 22966104    Smarty_Internal_SmartyTemplateCompiler->doCompile( string(4272), bool ) .../smarty_internal_templatecompilerbase.php:396
    17  87.0689 24537000    Smarty_Internal_Templateparser->doParse( long, string(1) )  .../smarty_internal_smartytemplatecompiler.php:114
    18  87.0689 24537584    Smarty_Internal_Templateparser->yy_reduce( long )   .../smarty_internal_templateparser.php:2398
    19  87.0689 24537792    Smarty_Internal_Templateparser->yy_r57( )   .../smarty_internal_templateparser.php:2303
    20  87.0689 24538008    Smarty_Internal_TemplateCompilerBase->compileTag( string(10), array(0), ??? )   .../smarty_internal_templateparser.php:1585
    21  87.0690 24538368    Smarty_Internal_TemplateCompilerBase->compileTag2( string(10), array(0), array(0) ) .../smarty_internal_templatecompilerbase.php:462
    22  87.0690 24538416    Smarty_Internal_TemplateCompilerBase->callTagCompiler( string(10), array(0), array(0), ???, ??? )   .../smarty_internal_templatecompilerbase.php:495
    23  87.0690 24541352    Smarty_Internal_Compile_Blockclose->compile( array(0), object(Smarty_Internal_SmartyTemplateCompiler)[1814], array(0), null, null ) .../smarty_internal_templatecompilerbase.php:761
    
    opened by Gamesh 13
  • Smarty property 'sub_template' does not exist

    Smarty property 'sub_template' does not exist

    Hi,

    After upgrade from Smarty 3.1.27 to 3.1.29 i am receiving this error:

    Smarty property 'sub_template' does not exist

    It is throwred by the file smarty_internal_extension_handler.php at the line 92.

    Someone knows how can i solve this?

    Thanks!

    opened by masimao 13
  • Authorization to use a Monochrome Smarty SVG logo

    Authorization to use a Monochrome Smarty SVG logo

    opened by estebangarviso 0
  • Add PHP 8.1 compatibility

    Add PHP 8.1 compatibility

    The goal of this PR is to make smarty compatible with PHP 8.1.

    The main issue was the use of the function strftime() which is deprecated in PHP 8.1. This problem is solve by the use of IntlDateFormatter after being sure that the intl extension is loaded.

    Other deprecations have been removed too.

    waiting 
    opened by atomiix 4
  • instanceof cannot be called on return value of a function Smarty-3.1.39

    instanceof cannot be called on return value of a function Smarty-3.1.39

    this works

    {if $object instanceof SomeClass}yes{/if}
    

    This does not (eventhough it used to under php 7.4 and Smarty 3.1.14). Problem occurs with php8.0 and pph7.4

    {if get_object() instanceof SomeClass}yes{/if}
    

    workaround is:

    {$object = get_object()}
    {if $object instanceof SomeClass}yes{/if}
    

    somewhat related to https://github.com/smarty-php/smarty/issues/191

    opened by oschonrock 4
  • Object properties cannot be called directly after a method

    Object properties cannot be called directly after a method

    <p>{{ hello()->total() }}</p>
    

    hello()The method returns an object

    opened by ghost 2
  • strftime deprecated in PHP 8.1

    strftime deprecated in PHP 8.1

    Unknown: Function strftime() is deprecated in file /Smarty_Compiler.class.php line 395
    Unknown: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in file /Smarty_Compiler.class.php line 1531
    
    opened by mambax7 6
  • Smarty is not compatible with PHP 8.1

    Smarty is not compatible with PHP 8.1

    https://github.com/php/php-src/blob/php-8.1.0RC4/UPGRADING

    https://www.php.net/index.php#id2021-07-22-1

    For example, this patch causes a fatal error

    aim-server[~/www/smarty/demo]$ gitdiff .
    diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl
    index 1fbb6d37..1e125e15 100644
    --- a/demo/templates/index.tpl
    +++ b/demo/templates/index.tpl
    @@ -1,6 +1,6 @@
     {config_load file="test.conf" section="setup"}
     {include file="header.tpl" title=foo}
    -
    +{php}{/php}
     <PRE>
     
     {* bold and title are read from the config file *}
    
    Fatal error: Type of SmartyCompilerException::$line must be int (as in class Exception) in public_html/smarty/libs/sysplugins/smartycompilerexception.php on line 8
    

    The expected error is

    Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:public_html/smarty/demo/templates/index.tpl" on line 3 "{php}{/php}" {php}{/php} tags not allowed. Use SmartyBC to enable them <-- thrown in public_html/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 3
    
    opened by ildar-aim 6
  • Unknown encoding when upgrade to the latest version

    Unknown encoding when upgrade to the latest version

    I'm new to this but why are unknown character from a contact form when we upgrade to the latest version

    Can be validated inside source code Smarty why is not seen an example character? đpđpđpđ

    Nothing was modified at server except Smarty version and its connection to the web app. When files are validated, it is also UTF-8 as encoding and Unix format. So, it is related to the settings inside Smarty source code or even some files should be verified as UNIX, UTF-8 inside Smarty source code.

    opened by toplisek 1
  • Append target file ext/name to tmp file (speedup antivirus scans)

    Append target file ext/name to tmp file (speedup antivirus scans)

    No file extension causes issues with Microsoft Antivirus, this simple update increase performance about 5x.

    Was super hard to debug, but once ".php" suffix is added, performance is fixed consistently on Windows.

    A bugfix release should be done once merged.

    opened by mvorisek 3
  • `Smarty::_realpath` method normalizes `://host/path` to `:\\host\path` on Windows

    `Smarty::_realpath` method normalizes `://host/path` to `:\\host\path` on Windows

    For local paths, I propose to normalize \ to / on every platform and drop DIRECTORY_SEPARATOR completely as / separator is fine to be used on Windows as well. This is also how Symfony normalizes local paths.

    opened by mvorisek 0
  • Bitwise operations give incorrect results

    Bitwise operations give incorrect results

    It appears bitwise operations when both numbers aren't in the same format fail. 2&2 and 0x2&0x2 seem to work while 2&0x2 returns 0.

    Code: 1: {2&0x2}

    Results: Version 3.1.15: 1:0

    Version 3.1.14: 1:2

    opened by ymTm7KuhCnIjkZAl2x2m2 0
Releases(v4.0.0)
Owner
Smarty PHP Template Engine
Smarty PHP Template Engine
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 5 Nov 3, 2021
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 5 Nov 3, 2021
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

Foil PHP 163 Nov 20, 2021
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.

Latte: amazing template engine for PHP Introduction Latte is a template engine for PHP which eases your work and ensures the output is protected again

Nette Foundation 731 Nov 27, 2021
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 145 Aug 13, 2021
⚡️ Simple and fastly template engine for PHP

EasyTpl ⚡️ Simple and fastly template engine for PHP Features It's simple, lightweight and fastly. No learning costs, syntax like PHP template It is s

PHPPkg 9 Nov 26, 2021
Standalone Skeltch templating engine for PHP

SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use from outside the framework.

glowie 1 Nov 5, 2021
SwitchBlade: Custom Directives for the Laravel Blade templating engine

SwitchBlade: Custom Directives for the Laravel Blade templating engine

Awkward Ideas 9 Sep 2, 2021
Twig, the flexible, fast, and secure template language for PHP

Twig, the flexible, fast, and secure template language for PHP Twig is a template language for PHP, released under the new BSD license (code and docum

Twig 7.3k Nov 24, 2021
Native PHP template system

Plates Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent Twig template engine and str

The League of Extraordinary Packages 1.3k Nov 19, 2021
A complete and fully-functional implementation of the Jade template language for PHP

Tale Jade for PHP Finally a fully-functional, complete and clean port of the Jade language to PHP — Abraham Lincoln The Tale Jade Template Engine brin

Talesoft 93 May 4, 2021
A ready-to-use Model View Controller template in PHP

PHP-MVC-Template A ready-to-use Model View Controller template in PHP Use this repo as a template! (Or clone it) Start to configure your MVC file Afte

Loule | Louis 6 Nov 19, 2021
Provides a GitHub repository template for a PHP package, using GitHub actions.

php-package-template Installation ?? This is a great place for showing how to install the package, see below: Run $ composer require ergebnis/php-pack

null 260 Nov 24, 2021
A lightweight template parser used by PyroCMS.

Lex Lex is a lightweight template parser. Lex is released under the MIT License and is Copyrighted 2011 - 2014 PyroCMS Team. Change Log 2.3.2 Convert

PyroCMS 103 Nov 15, 2021
Laravel package template

REPLACE Simple and flexible package template. Usage Replace all occurances of REPLACE (case sensitive) with the name of the package namespace. E.g. th

ARCHTECH 47 Nov 24, 2021
The Templating component provides all the tools needed to build any kind of template system.

Templating Component The Templating component provides all the tools needed to build any kind of template system. It provides an infrastructure to loa

Symfony 982 Nov 23, 2021
Document templates Laravel package is intended for creating/managing user editable document template

Document Templates Introduction Document templates Laravel package is intended for creating/managing user editable document templates, with ability to

42coders 99 Nov 14, 2021
A SilverStripe Module with template methods to quickly make use of FocusPoint, LazySizes, and Object-fit

LazyFocusFit A SilverStripe module with template methods to quickly make use of FocusPoint, LazySizes and object-fit. Requirements PHP FocusPoint JS/C

Evans Hunt 8 Oct 12, 2021
Astroid Framework - Powerful Joomla Template Framework

Powerful framework for designers and developers to create responsive, fast & robust Joomla based websites and templates.

TemPlaza 9 Nov 23, 2021