mangoweb/latte-bundle

Latte templating engine for Symfony

v1.1.0 2021-01-05 15:51 UTC

This package is auto-updated.

Last update: 2024-11-06 17:58:28 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.

See Symfony doc - csrf_token

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, optional
  • locale - 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, required
  • domain - string, optional
  • locale - string, optional
Example
{="my.awesome.translation.key"|translateChoice:5:['%name%' => 'Karel','%job%' => 'Metař']}

How to expand

Macros

Simple macro

Advanced macro

  • Implement directly \Latte\IMacro
  • Register service and mark it with service tag - { name: latte.advanced_macro, macro_name: fooBar }

Filters

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