Why isn't my Twig replace filter working with craft.request.getUrl()? I'm rendering some HTML into a variable. On this HTML I want to replace a value using craft.request.getUrl() but the value doesn't seem to get replaced. Any idea what I'm doing wrong?

{% set pages %}
    {% set entries = craft.entries.section('pages') %}
    {% for entry in entries %}
         &lt;a href="{{ entry.url }}" data-url="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
    {% endfor %}
{% endset %}

{{ pages|replace({'data-url="{{ craft.request.getUrl() }}"': 'class="active"'})|raw }}
Try:

{{ pages|replace({('data-url="' ~ craft.request.getUrl() ~ '"'): 'class="active"'})|raw }}


You were double nesting Twig tags {{ {{ }} }}, which is never necessary.  You'll want to use string concatenation instead. Also for dynamic keys in twig you need parentheses.