I have an entry id in that I am storing in a variable that I would like to access outside of this for statement, is there a way I can "stash" it somewhere? I want to do another query based on tags but make sure I exclude this entry id.

{% for entry in manualPost.all() %}

    {% set manualPostID = entry.id %}

    {% if entry.blogHero|length %}

        {% set optimizedImages = entry.blogHero.one().optimizedimages %}

        <a href="{{ entry.url }}"><img src="{{ optimizedImages.src() }}"srcset="{{ optimizedImages.srcset() }}"sizes="100vw" /></a>

    {% endif %}

    <a href="{{ entry.url }}">{{ entry.title }}</a>

{% endfor %}

1 Answer 1


Twig doesn't let you stash variables for access elsewhere; rather every variable has a well defined scope. So what you'd have to do is store that id in a variable that has a global context, so other templates you include can access it.

See the Twig Processing Order & Scope article for more info on this.

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.