pug-php / pug-symfony

Pug (Jade) template engine for Symfony
MIT License
44 stars 3 forks source link

Unable to generate route #25

Closed wtty closed 6 years ago

wtty commented 6 years ago

I installed pug-symfony in Symfony 4 with no issues but routes are not working for me:

The following route works in twig:

<a href="{{ path('some_route') }}">Home</a>

In pug:

a(href=path('some_route')) Home

It throws this error: Function name must be a string

kylekatarnls commented 6 years ago

This syntax worked fro Symfony 3, not tested in real case with Symfony 4. You can try the complete. Here are the short-cuts supposed to be implemented: https://github.com/pug-php/pug-symfony/blob/master/src/Jade/JadeSymfonyEngine.php#L138

So you can try a(href=view.router.path('some_route'))

wtty commented 6 years ago

Those would be great, being able to use translations in pug would be nice too {{ title('page_title'|trans) }} I tried what you suggested, but it didn't work:

Use of undefined constant view - assumed 'view'

The asset function doesn't seem to work either:

link(rel="stylesheet" href=asset('/build/style.css'))

Error:

Undefined index: assets
kylekatarnls commented 6 years ago

Oh, I guess, you set expressionLanguage to php, so you can't use JS-style:

a(href=$view['router']->path('some_route'))

The trans filter just call the symfony translator under the hood, you can pass the translator instance as a local or shared variables to views then just call the method.

wtty commented 6 years ago

I also tried that, but get the following:

Use of undefined constant router - assumed 'router'

Oh ok, I will keep that in mind.