Twig variable as link

I stuck at a serious simple problem. I try to loop over Grav pages and dynamically output there links.

{% for news in page.find('/aktuelles').children.order('header.news_date', 'asc').slice(0, 3) %}
<div class="recent-news">
    <a href="{{ news.url }}">
    <span>{{ news.header.news_date|date("d.m.Y") }}</span>
    {{ news.title }}
{% endfor %}

Unfortunatly the Twig code

{{ news.url }}

doesnt get replaced by the value behind the variable. Instead the generated link looks like this{{%20news.url%20}}. I tested the variable capsuled in the a-Tag. That worked! Does anybody know why twig can´t be rendered in _a_´s href-Attribute and have a workaround for me? Thanks!

Is there someone who knows what to do?

It’s strange, it seems that Twig is not parsed. But since you’re in the loop, and the title is shown, Twig is processing.

Moving it outside the <a> tag works?

yes, also moving outside the href works. My only actual workaround right now is to write the url in data-href and replace href on DOM load with the value with JS.

I don’t know why it’s not working, but you could try this workaround :
Define a variable :

{% set newsLink = news.url %}

Then use the variable instead of news.url :

<a href="{{ newsLink }}"></a>

Thanks for your nice idea. Also tried it, but also not working. Twig got not parsed in the a´s href.

Could you try to take the <a> out of the <div> ?

I’m asking that because I found a post talking about an issue quite similar :

Oh wow! That is actually working but not a charm for my HTML markup :smiley:

Is there another aproach to fix it on this way?