https://github.com/cleatsquad/magento2-smarty
The module is an integration of the Smarty template engine in Magento2.
https://github.com/cleatsquad/magento2-smarty
magento2 magento2-module smarty smarty-template-engine
Last synced: over 1 year ago
JSON representation
The module is an integration of the Smarty template engine in Magento2.
- Host: GitHub
- URL: https://github.com/cleatsquad/magento2-smarty
- Owner: CleatSquad
- License: mit
- Created: 2021-11-15T13:04:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-12T00:57:21.000Z (about 2 years ago)
- Last Synced: 2025-01-13T19:52:04.435Z (over 1 year ago)
- Topics: magento2, magento2-module, smarty, smarty-template-engine
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CleatSquad Magento 2 Smarty
[](https://packagist.org/packages/cleatsquad/magento2-smarty/stats)
[](https://packagist.org/packages/cleatsquad/magento2-smarty)
[](https://github.com/cleatsquad/magento2-smarty/blob/main/LICENSE)
## Magento Version Support

## Purpose
`CleatSquad_Smarty` is a Magento 2 module is an integration of the [Smarty](https://www.smarty.net/) 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 `.tpl` files.
## Getting Started
This module is intended to be installed via [Composer](https://getcomposer.org/). To add it to your Magento 2 project, follow these steps:
### Installation
1. **Download the package**
```bash
composer require cleatsquad/magento2-smarty
```
2. **Enable the module**
```bash
./bin/magento module:enable CleatSquad_Smarty
./bin/magento setup:upgrade
```
## Magento 2
### Components
A new engine has been added to this module which will allow you to use smarty. and this the injection of the new engine in the class 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
```xml
```
#### Example header.phtml converted to header.tpl
```php
getCssClass() ? ' ' . $block->getCssClass() : '';
$titleHtml = '';
if (trim($block->getPageHeading())) {
$titleHtml = 'getAddBaseAttribute()
. '>'
. $block->escapeHtml($block->getPageHeading())
. '';
}
?>
getId()) : ?> id="= $block->escapeHtmlAttr($block->getId()) ?>"
getAddBaseAttributeAria()) : ?>
aria-labelledby="= $block->escapeHtmlAttr($block->getAddBaseAttributeAria()) ?>"
>
= /* @noEscape */ $titleHtml ?>
= $block->getChildHtml() ?>
```
```tpl
{if ($block->getCssClass())}
{assign var = "cssClass" value = {$block->getCssClass()}}}
{else}
{assign var = "cssClass" value = ''}}
{/if}
{if (trim($block->getPageHeading()))}
{assign var = "titleHtml" value = 'getAddBaseAttribute()}>{$block->escapeHtml($block->getPageHeading())}'}
{else}
{assign var = "titleHtml" value = ''}}
{/if}
{if ($titleHtml)}
getId()) : ?> id={$block->escapeHtmlAttr($block->getId())}"{/if}
{if ($block->getAddBaseAttributeAria()) : ?>
aria-labelledby="{$block->escapeHtmlAttr($block->getAddBaseAttributeAria())}"
{/if}>
{$titleHtml}
{$block->getChildHtml()}
{/if}
```
```xml
```
#### Example breadcrumbs.phtml converted to breadcrumbs.tpl
```php
```
```tpl
{if $crumbs}
{/if}
```
#### Access helper methods
Write in your `.tpl` file:
```tpl
{assign var = "directoryHelper" value = $this->helper("Magento\Directory\Helper\Data")}
{$directoryHelper->getDefaultCountry()}
```
### Configurations
Configuration options can be found Stores -> Settings -> Configuration -> Advanced -> Developer -> Smarty.
| Section | Group | Field | Description |
| ------ | ----- | ----- | ----------- |
| dev | smarty | debug | Disable/Enable debug mode. |
| dev | smarty| cache | Disable/Enable of the cache of smarty templates (cache stored in var/cache/smarty) |
## Support
If you need help or have a question, you can:
- Open an issue through GitHub for bug reports and feature requests.
- Check the [Magento Community Forums](https://community.magento.com/) for general questions and support on Magento.
- Check on [Magento Stack Exchange](https://magento.stackexchange.com/) for general programming questions.
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/cleatsquad/magento-smarty/tags).
## Authors
- **Mohamed EL Mrabet** - *Initial work* - [mimou78](https://github.com/mimou78)
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.