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

Access collections using bracket notation #680

Closed
hacknug opened this issue Sep 4, 2019 · 3 comments
Closed

Access collections using bracket notation #680

hacknug opened this issue Sep 4, 2019 · 3 comments

Comments

@hacknug
Copy link

hacknug commented Sep 4, 2019

Is your feature request related to a problem? Please describe.
I'm trying to create an include that renders the navigation for a given collection.

This collection is contextual and linked directly to the one and only tag each page is set to. tags[0] holds the name of my collection eg: apples.

I can access collections.apples with no issues (as expected) but I can not write collections[ "apples" ] (nor collections[ tags[0] ], of course).

Describe the solution you'd like
I'd like to be able to use bracket notation to access collections as exposed.

Describe alternatives you've considered
Using a shortcode that takes tags[0] as an argument would solve my issue if I was able to access all collections inside the shortcode function (maybe this is already possible and I've missed it?).

Additional context
Ended up adding a shortcode that takes collections and tags[0] as arguments so I could search and replace with a regex.

@pieterbeulque
Copy link

pieterbeulque commented Sep 5, 2019

What templating engine are you working with?

@hacknug
Copy link
Author

hacknug commented Sep 6, 2019

Liquid. Sorry, forgot to mention that 😅

zachleat added a commit that referenced this issue Jul 11, 2020
zachleat added a commit that referenced this issue Jul 11, 2020
@zachleat
Copy link
Member

Looks like there are some limitations with Liquidjs here.

I added a bunch of tests here, you can have a look: https://github.com/11ty/eleventy/blob/master/test/TemplateRenderLiquidTest.js#L980

The ones prefixed with test.skip are failures.

The short answer here is that you need to remove your spaces around your quoted strings. collections["apples"] works but collections[ "apples" ] fails.

Also test[ref] works but test[ref[0]] fails. You could probably work around this by assigning ref[0] to a new value before you use it.

This might improve when the liquid upgrade ships #469. I’ll try to unskip the tests when that happens.

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

No branches or pull requests

3 participants