bertptrs / marty
Smarty view renderer for the Mako framework
Installs: 14 282
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 4
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- mako/framework: ^6.0 || ^7.0 || ^8.0
- smarty/smarty: ^3 || ^4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- php-parallel-lint/php-parallel-lint: ^1.2
- phpro/grumphp: ^0.19 || ^1
- phpunit/phpunit: ^8.0 || ^9.0
Suggests
- phpunit/phpunit: Test whether templates actually compile in your unit tests.
README
Marty is a simple Smarty view renderer for the Mako framework.
Requirements
Marty has been tested on all current Mako versions. Any other version may work, but has not been tested. Unit tests are run against PHP 7.0 and up. Smarty 3 or 4 is required, but will be pulled in as part of the installation.
Installation
Marty can be added to your Mako project using composer! Just add it to your requirements
{ /* Stuff */ require: { /* Your other requirements */ "bertptrs/marty": "*" } /* The rest of your composer.json*/ }
Usage
Once installed, you will need to add it to your packages list. You do
this by adding it to the "Web" packages. This is located in the file
app/config/application.php
.
<?php return [ // … 'packages' => [ // … 'web' => [ 'marty\MartyPackage', ], ], // … ]; ?>
This enables the Smarty View renderer for every view with the ".tpl" file extension.
Configuration
Configuration can be done by changing the marty::smarty
configuration.
Just refer to the Mako documentation on package
configuration
for details.
The configuration properties are as follows:
Plugins
Marty supports the plugin structure offered by Smarty, and extends it to use the dependency injector offered by the Mako framework.
Plugin dirs can be added to the config. The structure for plugins can be found in the Smarty Documentation. Due to the fact that Mako resolves parameters by name, Smarty plugin parameters should have their names as specified in the documentation. This means that the parameters should be named as follows:
- Template functions:
- parameters should be named
$params
- The smarty template should be named
$template
- parameters should be named
- Modifiers:
- The input data should be named
$value
- Any other values will be stored in array
$params
in order.
- The input data should be named
- Block functions:
- Call parameters should be named
$params
- The block content should be named
$content
- The template reference should be named
$template
- The repetition flag should be named
$repeat
.
- Call parameters should be named
- Compiler functions:
- Call parameters should be named
$params
- The Smarty reference should be named
$smarty
- Call parameters should be named
As an example, we can build a small plugin that uses the I18n module of the framework.
function smarty_modifier_i18n($value, mako\i18n\I18n $i18n) { return $i18n->get($value); }
Then, we can use your plugin like this:
Lets show {'some.translated.text'|i18n}.
Contributing
If there are any features in Smarty that cannot (easily) be used in the current package, or if there are Mako features that are hard to bind to Smarty, feel free to file an issue or a pull request.
Code style and such are ran using GrumPHP. Make sure that your files are in accordance to those rules.