Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

Problem with shortcodes in subpages

first-time

Started by ptrxyz 6 years ago · 2 replies · 520 views
6 years ago

I am looping over a page's subpages using {% for p of page.collection %} and then dump the shortcodes using
{{ dump(p.contentMeta.shortcodeMeta.shortcode) }} .

The dump of the shortcode object always contains the values of the very first subpage (while p.raw_content is correct). I think that's ... wrong. Or am I doing it wrong? I would assume, that p.contentMeta.shortcodeMeta should always be the shortcodes of the page that p refers to.


So as an example, if I have three subpages, each one containing this (with an increasing number for example):

TXT
[section name="text"]This is from subpage 1[/section]

and my main page looks like this:

TWIG
{% for p in page.collection %}
{{ dump(p.contentMeta.shortcodeMeta.shortcode.section.text) }}
{% endfor %}

the output is

TXT
This is from subpage 1
This is from subpage 1
This is from subpage 1

instead of

TXT
This is from subpage 1
This is from subpage 2
This is from subpage 3

which is what I would expect...

I am super new to this whole Twig world, am I doing it wrong? Any help would be appreciated. 🙂

6 years ago

@ptrxyz, I can reproduce the issue and added a reproducible test case to the issue you submitted at the repo of 'grav-plugin-shortcode-core'

👍 1
6 years ago

Thanks! I hope we can fix this at some point.

Suggested topics

Topic Participants Replies Views Activity
General · by Hanns Mattes, 2 days ago
1 47 1 day ago
General · by Andy Miller, 1 day ago
0 39 1 day ago
General · by Jerry Hunt, 6 days ago
2 160 3 days ago
General · by pamtbaau, 3 days ago
1 109 3 days ago
General · by Andy Miller, 3 days ago
0 93 3 days ago