Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twig loop.parent.loop not there for nested loops #4271

Closed
marionnewlevant opened this issue May 15, 2019 · 1 comment
Closed

twig loop.parent.loop not there for nested loops #4271

marionnewlevant opened this issue May 15, 2019 · 1 comment

Comments

@marionnewlevant
Copy link

Description

This used to work, and does work in twigfiddle:

{% for x in 1..2 %}
  {% for y in 1..2 %}
    [{{loop.parent.loop.index}} {{loop.index}}]
  {% endfor %}
{% endfor %}

Steps to reproduce

  1. Brand new Craft install (3.1.27)
  2. Create a twig template with that content
  3. Error is:

Key "loop" for array with keys "view, devMode, SORT_ASC, SORT_DESC, SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_LOCALE_STRING, SORT_NATURAL, SORT_FLAG_CASE, POS_HEAD, POS_BEGIN, POS_END, POS_READY, POS_LOAD, isInstalled, loginUrl, logoutUrl, now, craft, currentUser, systemName, currentSite, siteName, siteUrl, _parent, _seq, x, _key" does not exist.

Additional info

  • Craft version: 3.1.27
  • PHP version: 7.0.13
  • Twig version: 2.8.1
  • Plugins & versions: none

Looking at the compiled template, and comparing it to the compiled template from twigfiddle it is pretty clear what is going wrong.
compiledTemplateComparison.zip

@brandonkelly
Copy link
Member

brandonkelly commented May 28, 2019

Sorry for the delay Marion! Just fixed this for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#c77cb93ba9c0a448abee7bf5ce263a84431517f8 as 3.1.28",
  "...": "..."
}

Then run composer update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants