2
votes

I am using Slim Framework and Twig.

I want to apply the DRY by using partials. I have a form that is reused in several views with different variables such as titles and route (url) names.

I am struggling on how to make it work on url names.

For example, there is this link using the ´urlFor´ helper with parameter as follows inside a view:

<a href="{{urlFor('route.name', {parameter: value})}}">The link</a>

So that is the link I want to pass to the partial template since, it is different in each view, I want to use the partial form. I have tried several approaches but it does not work. I don't know how to pass this string containing ' inside.

For example, I have tried this partial call inside the parent view like this:

{% include 'partials/partial.php' with {'theUrl': "urlFor('route.name', {parameter: value})"} %}

And inside the partial like this:

<a href="{{theUrl}}">Show more</a>

It does not work because in the browser's url I see the following:

http://myproject.dev/pages/urlFor('route.name',%20%7Bparameter:%201%7D)

It looks like it is not being escaped properly. Any ideas how to fix this when passing route names with urlFor()?

1

1 Answers

5
votes

Without the greatest possibility for testing i think i found the problem. You are simply adding the function inside a string and that does not give the parser an oportunity to resolve the method, because it's basicly just a string.

{% include 'partials/partial.php' with {'theUrl': "urlFor('route.name',{parameter: value})"} %}

Should be

{% include 'partials/partial.php' with {'theUrl': urlFor('route.name',{parameter: value})} %}