mangoweb / latte-bundle
Latte templating engine for Symfony
Installs: 28
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 5
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1|^8.0
- latte/latte: ^2.5
- nette/forms: ^3.0
- nette/utils: ^3.0
- symfony/framework-bundle: ^4.1|^5.0
- symfony/http-kernel: ^4.1|^5.0
Requires (Dev)
- phpstan/phpstan: ^0.12
- roave/security-advisories: dev-master
- symfony/security-bundle: ^4.1|^5.0
- symfony/translation: ^4.1|^5.0
This package is auto-updated.
Last update: 2024-12-06 18:18:19 UTC
README
How to install
- Just install it as standard symfony bundle
- Then just ask for
Latte\Engine
service
Latte
Symfony specific macros
renderRoute
Makes a request to the given route and prints the result.
Spec
{renderRoute <routeName>[, 'routeParams'=>[(<key> => <value>,)...][, 'renderOptions'=>[(<key> => <value>,)...]}
Example
{renderRoute myAwesomeRoute,'routeParams'=>['x' => 5, 'y' => 7],'renderOptions'=>['strategy' => 'inline']}
routePath
Print the relative URL (without the scheme and host) for the given route.
Spec
{routePath <routeName>[,<key> => <value>]...}
<a n:href="<routeName>[,<key> => <value>]...">
Example
{routePath myAwesomeRoute,'x' => 5,'y' => 7}
<a n:href="myAwesomeRoute,'x' => 5,'y' => 7"></a>
routeUrl
Print the absolute URL (with scheme and host) for the given route.
Spec
{routeUrl <routeName>[,<key> => <value>]...}
Example
{routeUrl myAwesomeRoute,'x' => 5,'y' => 7}
relativePath
Returns the relative path from the passed absolute URL. See Symfony doc - relative_path
Spec
{relativePath <absoluteUrl>}
Example
{relativePath 'http://example.com/human.txt'}
absoluteUrl
Returns the absolute URL from the passed relative path.
Spec
{absoluteUrl <relativePath>}
Example
{absoluteUrl 'human.txt'}
csrfToken
Renders a CSRF token. Use this function if you want CSRF protection without creating a form.
Spec
{csrfToken <intention>}
logoutUrl - logoutPath
Generates a absolute/relative logout URL for the given firewall. If no key is provided, the URL is generated for the current firewall the user is logged into.
Spec
{logoutPath [key]}
{logoutUrl [key]}
Symfony filters
translate
See Symfony docs - translation in templates
Spec
{="<translation.key>"|translate[:[(<argumentName> => <argumentValue>,)...]][:<domain>][:<locale>]}
{_"<translation.key>"}
domain
- string, optionallocale
- string, optional
Example
{="my.awesome.translation.key"|translate:['%name%' => 'Karel','%job%' => 'Metař']} {="my.awesome.translation.key"}
translateChoice
See Symfony docs - translation in templates
Spec
{="<translation.key>"|translateChoice:<count>[:[(<argumentName> => <argumentValue>,)...]][:<domain>][:<locale>]}
count
- int, requireddomain
- string, optionallocale
- string, optional
Example
{="my.awesome.translation.key"|translateChoice:5:['%name%' => 'Karel','%job%' => 'Metař']}
How to expand
Macros
Simple macro
- Class
\Mangoweb\LatteBundle\Macro\SimpleMacro
is wrapper for macroSet->addMacro() (see https://latte.nette.org/en/#toc-user-defined-macros) - Extend class and mark service with service tag
- { name: latte.simple_macro }
- Or Implement
\Mangoweb\LatteBundle\Macro\ISimpleMacroProvider
and mark it with service tag- { name: latte.simple_macro_provider }
Advanced macro
- Implement directly
\Latte\IMacro
- Register service and mark it with service tag
- { name: latte.advanced_macro, macro_name: fooBar }
Filters
Filter provider
- Implement
\Mangoweb\LatteBundle\Filter\IFilterProvider
- Mark service with service tags:
{name: 'latte.filter_provider'}
Providers
- Create service and tag it with
- {name: 'latte.provider', provider_name: fooBar }
- This will then be avabile at runtime in latte via
$this->global->fooBar