I'm developing a navigation system for Symfony 2. It's working really nicely so far. So far, there is a config file like so:
# The menu name ...
primary:
# An item in the menu ...
Home:
enabled: 1
# Routes where the menu item should be shown as 'active' ...
routes:
- "a_route_name"
# Where the link goes to ... the problem ...
target: "a_route_name"
This layout is working nicely, and the menu works. Apart from in my template, I can only generate links using the target value that correspond to routes within an application; i.e, not an external URL.
The template is as follows for generating the navigation:
{# This is what puts the data for the menu into the page currently ... #}
{% set primary_nav = menu_data('primary') %}
<nav role="navigation" class="primary-nav">
<ul class="clearfix">
{% for key, item in primary_nav if item.enabled is defined and item.enabled %}
{% if item.routes is defined and app.request.attributes.get('_route') in item.routes %}
<li class="active">
{% else %}
<li>
{% endif %}
{% if item.target is defined %}
<a href="{{ path(item.target) }}">{{ key }}</a>
{% else %}
{{ key }}
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
Is there a simple way to allow the path()
function or, something similar to generate URLs from routes, or just simply use a given URL if it validates as one?
I got as far as trying url()
, and looked around the docs but couldn't see anything.