dev-master
9999999-dev http://github.com/marcoshoo/phptal-laravelPHPTAL for Laravel 5.x
MIT
The Requires
- php >=5.5.9
- phptal/phptal dev-master
- laravel/framework 5.*
by Levi Stanley
by Marcos Soares
laravel phptal
Wallogit.com
2017 © Pedro Peláez
PHPTAL for Laravel 5.x
Allows you to use PHPTAL seamlessly in Laravel, (*1)
Add MarcosHoo\LaravelPHPTAL as a requirement to composer.json:, (*2)
{
"require": {
"phptal/phptal": "dev-master",
"marcoshoo/phptal-laravel": "dev-master"
}
}
Update your packages with composer update or install with composer install., (*3)
Once Composer has installed or updated your packages you need to register PHPTAL with Laravel. Open up app/config/app.php and find the providers key towards the bottom and add:, (*4)
MarcosHoo\LaravelPHPTAL\PHPTALServiceProvider::class,
Next step is copy example config to your config directory., (*5)
php ./artisan vendor:publish --provider 'MarcosHoo\LaravelPHPTAL\PHPTALServiceProvider'
Currently PHPTAL is set by default to HTML5, however, you can change this setting in its config.php file, XHTML, or XML., (*6)
PHPTAL also has a nice feature which you can use called filters, for example I have one that bust the cache for images, js, css, this is configurable via the config file., (*7)
'preFilters' => [
'bustCache',
'minimizeJs',
'adderJs'
]
You call the PHPTAL template like you would any other view:, (*8)
view('hello', [...])
PHPTALTranslator class uses Laravel translation service, so the translation files should be placed in the same translation files directory of the framework. Examples of how to use the a translation with id 'welcome' contained in a file called 'messages.php':, (*9)
<div i18n:domain="messages" i18n:translate="string:welcome"></div>
<div i18n:domain="messages" i18n:translate="">welcome</div>
<div i18n:translate="string:messages.welcome"></div>
<div i18n:translate="">messages.welcome</div>
Translation file:, (*10)
<?php
# File 'messages.php'
return [
'apples' => 'There is one apple|There are many apples',
'oranges' => '{0} There are none|[1,19] There are some|[20,Inf] There are many',
];
<div 18n:domain="messages" i18n:translate="string:apples|5">
<!--There are many apples -->
</div>
<span tal:define="q php:22" i18n:translate="string:messages.oranges|${q}">
<!--There are many -->
</span> oranges
<?php
# File 'messages.php'
return [
'welcome_ex1' => 'Welcome ${user}, you have ${mails} unread mails.',
'welcome_ex2' => 'Welcome :name!',
'welcome_ex3' => 'Welcome :anonymous!',
'anonymous' => 'anonymous user',
];
<div 18n:domain="messages" i18n:translate="string:welcome_ex1">
<span i18name="name" tal:replace="user/name"/>
<span i18name="name" tal:replace="user/nbrMails"/>
</div>
<div 18n:domain="messages" i18n:translate="string:welcome_ex1||user=${user/name}|mails=${user/nbrMails}">
</div>
<div tal:define="name user/name" 18n:domain="messages" i18n:translate="string:welcome_ex2"> </div>
<div 18n:domain="messages" i18n:translate="string:welcome_ex3">
<!-- Welcome anonymous user! -->
</div>
PHPTAL for Laravel 5.x
MIT
laravel phptal