Download the PHP package miko/laravel-latte without Composer
On this page you can find all versions of the php package miko/laravel-latte. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-latte
Laravel Latte
Extends the Laravel framework with the templating engine Latte
Installation
Then the templating engine is used according to the file extension:
*.blade.php
- Blade (Laravel default)*.latte
- Latte
Configuration
Publish config file into config/latte.php
:
Follow the instructions in the config file.
Extension
See https://latte.nette.org/tags
And additional:
Filter nl2br
(bool $xhtml = null
)
Default rendering as xhtml or html can be configured in the config file.
Tags {link}
and n:href
Similar to tags in Nette
except that the separator berween controller and method is not :
but @
and the default method is not default
but index
according to the Laravel conventions.
Basically this is a simplified call to Laravel's action() helper when
there is no need to write the entire FQCN and the word Controller
.
In addition, it is possible to use the keyword this
for the current action - then there is no need to write unchanged parameters.
(expand)
- the equivalent of...$arr
operator https://latte.nette.org/en/syntax#toc-a-window-into-history
Usage of this
route:
template:
At address mysite.com/users/permissions/1/2
generates link mysite.com/users/permissions/1/2?sort=date
Tags {asset}
and n:src
Adds the m
parameter to the URL with the timestamp of the last file change. Every time the file is changed, it will be reloaded
and there is no need to clear the browser cache:
Tags {csrf}
and {method}
Generate hidden inputs _token
and _method
in form.
See Preventing CSRF Requests
and Form Method Spoofing.
Rendering as xhtml or html can be configured in the config file.
Tags {livewire}
, {livewireStyles}
, {livewireScripts}
a {livewireScriptConfig}
🧪 Experimental
Tags for Livewire. They are only available if livewire is implemented.
Since Livewire renders its templates itself, the template can be a latte or a blade file.
⚠️ WARNING: if the component view is a latte file and the default layout is set in config (latte.layout
), the component view must have {layout none}
at the beginning.
Otherwise, Latte engine will try to render the layout again for this component.
resources/views/livewire/component-name.latte
:
Translation {_}
Laravel provides functions __()
and trans()
respectively, see retrieving translation strings,
and trans_choice()
, see Pluralization.
The tag {_}
can handle both, it depends on the second parameter, whether it is an integer or an array.
Above is equivalent to Laravel functions:
If you want to implement Latte\Essential\TranslatorExtension
as described in Latte doc,
you can do so in ServiceProvider
e.g. like this:
Why is it not implemented by default?
{translate}{/translate}
andn:translate
tag are tempting to use translation strings as keys for an entire paragraph, which seems like hell and leads to error rates.n:translate
doesn't work (v3.0.13)- setting the
lang
parameter as a cache key for precompiling static texts does not work if the language is set at runtime withApp::setLocale()
Components {x}
An object implementing Miko\LaravelLatte\IComponent
can be rendered in template:
View:
Root namespace of components is set in config (latte.components_namespace
)
and is App\View\Components
by default.
⚠️ WARNING: if the default layout is set in config (latte.layout
), the component view must have {layout none}
at the beginning.
Otherwise, Latte engine will try to render the layout again for this component.