1

I have this code:

href="{{ path('new') }}"

Now is necessary use one variable in this section:

href="{{ path(item.ruta) }}"

But this show a error:

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "" as such route does not exist.").

How can solution this problem?

juanitourquiza
  • 2,097
  • 1
  • 30
  • 52

1 Answers1

4

It seems that item.ruta is empty, so no route could be generated.

You could specifiy a fallback like this {{ path(item.ruta ? item.ruta : 'new') }} or if you want to stay on the current page you need to do something like descripted here: get current url in twig template?

{% if item.ruta %}
    href="{{ path(item.ruta) }}"
{% else %}
    href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) }}"
{% endif %}

or if you really want # only, then remove the path function call

{% if item.ruta %}
    href="{{ path(item.ruta) }}"
{% else %}
    href="#"
{% endif %}
Fabian Schmick
  • 1,616
  • 3
  • 23
  • 32