How To Pass A Twig Output String Into the urlFor() Function

570 views Asked by At

I would like to pass the id of a category into a parameter using urlFor().

{% for category in categories %}
<br>
<p><a href="{{urlFor('showTopic.post', {"cat_id": "{{category.id}}"})}}">{{category.category_title}}<a><br>{{category.category_description}}</p>
<br>
<br>
{% endfor %}

This currently does not work. It just passes in {{category.id}} instead of the actual id for the category. I have an id for each category in my database. If I try to use {{category.category_title}}, which I know works because it does output the title, I get the same thing. Thanks for the help

1

There are 1 answers

0
Med On BEST ANSWER

Try

<a href="{{urlFor('showTopic.post', {"cat_id": category.id})}}">{{category.category_title}}<a>

you don't need to surround category.id with {{ and }} because you already are in print mode