cleatsquad / magento-smarty
Smarty template engine for Magento 2
Package info
github.com/CleatSquad/magento2-smarty
Type:magento2-module
pkg:composer/cleatsquad/magento-smarty
Requires
- magento/framework: >=100.0.0
- magento/module-backend: >=100.0.0
- magento/module-config: >=100.0.0
- smarty/smarty: ^3.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^6.5
- sebastian/phpcpd: ^3.0
- squizlabs/php_codesniffer: ^3.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-01 06:40:27 UTC
README
Warning
This package is abandoned and no longer maintained. The repository is archived and the package is marked as abandoned on Packagist. No replacement is suggested: Magento 2 templates should use .phtml.
Known issue: in the last release, template variables other than $block / $this (e.g. $crumbs) all receive the value of $this, so the breadcrumbs example below does not work as is.
Magento Version Support
Purpose
CleatSquad_Smarty is a Magento 2 module that integrates the Smarty template engine in Magento2.
To use this package you need to write your Magento2 module, or you can write all your template files in Smarty.
This template engine is intended to be used in addition to the .phtml files.
Getting Started
This module is intended to be installed via Composer. To add it to your Magento 2 project, follow these steps:
Installation
-
Download the package
composer require cleatsquad/magento-smarty
-
Enable the module
./bin/magento module:enable CleatSquad_Smarty ./bin/magento setup:upgrade
Magento 2
Components
This module adds a Smarty template engine and registers it for the .tpl extension in Magento\Framework\View\TemplateEngineFactory.
Frontend Integration
Your template files must have the file extension .tpl to get automatically recognized.
In your layout xml files or blocks please specify the new template
<referenceBlock name="page.main.title" template="Magento_Theme::html/title.tpl"/>
Example title.phtml converted to title.tpl
<?php /** * @var $block \Magento\Theme\Block\Html\Title */ $cssClass = $block->getCssClass() ? ' ' . $block->getCssClass() : ''; $titleHtml = ''; if (trim($block->getPageHeading())) { $titleHtml = '<span class="base" data-ui-id="page-title-wrapper" ' . $block->getAddBaseAttribute() . '>' . $block->escapeHtml($block->getPageHeading()) . '</span>'; } ?> <?php if ($titleHtml) : ?> <div class="page-title-wrapper<?= $block->escapeHtmlAttr($cssClass) ?>"> <h1 class="page-title" <?php if ($block->getId()) : ?> id="<?= $block->escapeHtmlAttr($block->getId()) ?>" <?php endif; ?> <?php if ($block->getAddBaseAttributeAria()) : ?> aria-labelledby="<?= $block->escapeHtmlAttr($block->getAddBaseAttributeAria()) ?>" <?php endif; ?>> <?= /* @noEscape */ $titleHtml ?> </h1> <?= $block->getChildHtml() ?> </div> <?php endif; ?>
{if ($block->getCssClass())}
{assign var="cssClass" value=" {$block->getCssClass()}"}
{else}
{assign var="cssClass" value=''}
{/if}
{if (trim($block->getPageHeading()))}
{assign var = "titleHtml" value = '<span class="base" data-ui-id="page-title-wrapper" {$block->getAddBaseAttribute()}>{$block->escapeHtml($block->getPageHeading())}</span>'}
{else}
{assign var="titleHtml" value=''}
{/if}
{if ($titleHtml)}
<div class="page-title-wrapper{$block->escapeHtmlAttr($cssClass)}">
<h1 class="page-title"
{if ($block->getId())} id="{$block->escapeHtmlAttr($block->getId())}"{/if}
{if ($block->getAddBaseAttributeAria())}
aria-labelledby="{$block->escapeHtmlAttr($block->getAddBaseAttributeAria())}"
{/if}>
{$titleHtml}
</h1>
{$block->getChildHtml()}
</div>
{/if}
<referenceBlock name="breadcrumbs" template="Magento_Theme::html/breadcrumbs.tpl"/>
Example breadcrumbs.phtml converted to breadcrumbs.tpl
<?php if ($crumbs && is_array($crumbs)) : ?> <div class="breadcrumbs"> <ul class="items"> <?php foreach ($crumbs as $crumbName => $crumbInfo) : ?> <li class="item <?php echo $crumbName ?>"> <?php if ($crumbInfo['link']) : ?> <a href="<?php echo $crumbInfo['link'] ?>" title="<?php echo $this->escapeHtml($crumbInfo['title']) ?>"> <?php echo $this->escapeHtml($crumbInfo['label']) ?> </a> <?php elseif ($crumbInfo['last']) : ?> <strong><?php echo $this->escapeHtml($crumbInfo['label']) ?></strong> <?php else: ?> <?php echo $this->escapeHtml($crumbInfo['label']) ?> <?php endif; ?> </li> <?php endforeach; ?> </ul> </div> <?php endif; ?>
{if $crumbs}
<div class="breadcrumbs">
<ul class="items">
{foreach from=$crumbs key=crumbName item=crumbInfo}
<li class="item {$block->escapeHtmlAttr($crumbName)}">
{if $crumbInfo.link}
<a href="{$crumbInfo.link}" title="{$block->escapeHtmlAttr($crumbInfo.title)}">
{$block->escapeHtml($crumbInfo.label)}
</a>
{elseif $crumbInfo.last}
<strong>{$block->escapeHtml($crumbInfo.label)}</strong>
{else}
{$block->escapeHtml($crumbInfo.label)}
{/if}
</li>
{/foreach}
</ul>
</div>
{/if}
Access helper methods
Write in your .tpl file:
{assign var="directoryHelper" value=$this->helper("Magento\Directory\Helper\Data")}
{$directoryHelper->getDefaultCountry()}
Configurations
Configuration options can be found in Stores -> Settings -> Configuration -> Advanced -> Developer -> Smarty.
| Section | Group | Field | Description |
|---|---|---|---|
| dev | smarty | debug | Disable/Enable debug mode. |
| dev | smarty | cache | Disable/Enable the cache of Smarty templates (cache stored in var/cache/smarty) |
Support
This package is no longer supported. For general questions you can:
- Check the Magento Community Forums for general questions and support on Magento.
- Check on Magento Stack Exchange for general programming questions.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Mohamed EL Mrabet - Initial work - mimou78
License
This project is licensed under the MIT License - see the LICENSE file for details.