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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Can I access shortcode section from another page? how?

Solved by pamtbaau View solution

Started by Anna 1 year ago · 2 replies · 65 views
1 year ago

Hey everybody,

most of my pages have an “intro” section defined via shortcode. I display this in my twig template with this: {{ shortcode.section.intro|raw }}

Now I would like to access this from another page, in a list of child pages produced by a for loop, like so:

TWIG
{% for p in page.children.published %}
    {{ p.media.images|first.html()|raw }}
    {{ p.shortcode.section.intro|raw }}
{% endfor %}

However, in the loop p.shortcode returns null (whereas the image shows up fine, so I’m thinking shortcodes might just not work like that). Does anybody know how to solve this?

Many thanks for your time & thoughts!

1 year ago Solution

@Netzhexe, Have you had a chance to read the README of shortcode-core?

👍 1
1 year ago

Oh! Do you know, I had it open in another tab, but apparently I was blind yesterday?? Sorry about that, and thank you!

On the other hand, I changed tack after posting this and utilised Grav’s built-in summary function which I don’t think I’ve ever used for anything before, and it may actually be the better solution. But now I can consider the pros and cons of both, so that’s wonderful.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 42 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 47 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 71 2 months ago