Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Is there some way to use {% block... %} in link_to

Is there some way to use {% block... %} in link_to(). I am trying to use template inheritence. The below code adds literal {% block indexlink %}{% endblock %} into the link

<li class="previous">{{ link_to("{% block indexlink %}{% endblock %}", "Go Back") }}</li>

If I remove the double quotes then the compiler gives an error - unexpected token {%. If I remove {% blockand %} totally then it says Undefined variable: indexlink. Is there some way I can specify the link using a {% block... variable %}option.

Thanks



40.6k
Accepted
answer
edited Oct '17

No, but you can do this:

{% block indexLink %}
{% set indexLink = '/mylink' %}
{% endblock %}

<li class="previous">{{ link_to(indexLink, "Go Back") }}</li>

Or you could propagate a variable from the controller.