2

I need to set a bunch of variables to feed my html head metas. Most of the time the page is directly related to an entry but i also have pages for each user with a route that look like 'equipe/user.username':

{% if craft.request.getSegment(1) == 'equipe' and craft.request.getSegment(2) is defined %}
    {% set user = craft.users.username(craft.request.segment(2)).first()%}
    {% set title = user.username %}
    {% set description = user.description %}
    {% set resume = user.resume %}
    {% set url = siteUrl~'equipe/'~user.username %}
    {% for asset in user.imageHeader %}
        {% set imageUrl = asset.getUrl('header') %}
        {{ imageUrl }}
    {% endfor %}
{% else %}
    {% set title = entry.title %}
    {% set description = entry.description %}
    {% set resume = entry.resume %}
    {% set url = entry.url %}
    {% for asset in entry.imageHeader %}
        {% set imageUrl = asset.getUrl('header') %}
        {{ imageUrl }}
    {% endfor %}
{% endif %}
{{ imageUrl }}

Everything works fine except for the imageUrl variable. it behave like a local variable. I can retrieve the value just after it is set, but not outside of the for loop... any idea why ?

1 Answer 1

3

I found the solution to the issue... indeed it behave like a local variable ! if i want to use it outside of the for loop it seems that i have to set it before with something like:

{% set imageUrl = '' %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.