0

I'm getting related (tagged) news articles like this:

<property name="related" type="smart_content">
    <!-- @see https://docs.sulu.io/en/2.2/reference/content-types/smart_content.html -->
    <meta>
        <title lang="en">Related content</title>
        <title lang="de">Verwandte Inhalte </title>
    </meta>

    <params>
        <param name="provider" value="articles"/>
        <param name="types" value="news"/>
        <param name="max_per_page" value="3"/>
    </params>
</property>

It's like 3 articles of type "news". And in filter options (back-end) I set that those articles must be tagged with some specific tag(s).

From page twig template I can print those tags like:

    {% for related in content.related %}
        {% for tag in related.content.excerpt.tags %}
            {{ tag.name }} ({{ tag.id }})
        {% endfor %}
        <a href="{{ related.routePath }}">{{ related.title }}</a>
    {% endfor %}

Best I could achieve is getting tag name and id. How to get tag url? If I try something like:

 {{ sulu_tag_url(tag) }}

I get "Cannot use object of type Sulu\Bundle\ArticleBundle\Document\TagViewObject as array". Can I somehow use tag id to get it's url?

MilanG
  • 6,994
  • 2
  • 35
  • 64

1 Answers1

0

The sulu_tag_url extension expects an array instead of the TagViewObject.

The extension calls this method TagRequestHandler::setTagToUrl. The method requires only the name property of the tag, so your best bet is to create an object with the name of the tag.

e.g. {{ sulu_tag_url({'name': tag.name}) }}

But I agree with you, that it is not expected from the developer, that the sulu_tag_url extension expects a serialised Tag object. If you don't mind you can create an issue for this in the git repository.

Prokyon
  • 128
  • 7