We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Icon and Text Link Using Set and Link_to

Beginner Question: I'm trying to add icons before the text links for a nav i'm building - but struggling to do this using the framework - can anyone point me in the right direction? This works just to have the text and links, but say I want to add a small image before each value when the link is generated?

Thanks in advance

{%- set menus = [
    'HOME': 'home/index',
    'ALERTS': 'home/alerts',
    'SUPPORT': 'home/support',
    'CHAT': 'home/chat',
    'BANANA': 'home/banana'
] -%}

{%- for key, value in menus %}
      {% if value == dispatcher.getControllerName() ~ "/" ~ dispatcher.getActionName()  %}
          <li class="active">{{ link_to(value, key) }}</li>
      {% else %}
          <li>{{ link_to(value, key) }}</li>
      {% endif %}
{%- endfor -%}


85.5k

i dont use foreach for my navs, i write them 1 by 1. then you can just copy/paste what your frontend framework is offering

edited Feb '17

You can always exted Phalcon\Tag class and override linkTo method and set tag service to your class.