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

Shortcodes refer to wrong subpage when used in loop. #96

Open
ptrxyz opened this issue Jul 29, 2020 · 3 comments
Open

Shortcodes refer to wrong subpage when used in loop. #96

ptrxyz opened this issue Jul 29, 2020 · 3 comments

Comments

@ptrxyz
Copy link

ptrxyz commented Jul 29, 2020

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.

@pamtbaau
Copy link
Contributor

pamtbaau commented Jul 29, 2020

TLDR:

  • Empty cache, browse to parent ->both children in collection show section of child 1
  • When child page is updated -> its section is refreshed
  • Empty cache, browse to parent ->both children in collection show section of child 1 again
  • Empty cache, then browsing to either child 1 or 2, and then to parent -> both sections are shown

Steps to reproduce:

  • Fresh Grav 1.6.26 installation
  • Install plugin shorcode-core
  • Define collection with 2 child pages
    • Content child 1: [section name="text"]Section from child 1[/section]
    • Content child 2: [section name="text"]Section from child 2[/section]
  • Twig contains:
    {% for child in page.collection %}
        {{ child.contentMeta.shortcodeMeta.shortcode.section.text }}<br>
    {% endfor %}
    
  • Clear cache ->

    Section from child 1
    Section from child 1

  • Changed child 1 ->

    Section from child 11
    Section from child 1

  • Changed child 2 ->

    Section from child 11
    Section from child 22

  • Clear cache ->

    Section from child 11
    Section from child 11

  • Clear cache, browse to child 1 or 2 first, then to parent ->

    Section from child 11
    Section from child 22

@OleVik
Copy link

OleVik commented Jul 29, 2020

So you'll have to evaluate the Page by forcing the caching by navigating there? That seems like a very painstaking process. I suggested on Discord that he use FrontMatter instead as that's more readily available and easier to maintain validation for in editing from Admin.

@npetri13
Copy link

npetri13 commented Jan 5, 2021

I have the same issue with a template which i wrote in 2018. It was working, when it was delivered. So this might help. Sorry but i cannot say when exactly the code didnt work anymore. I've got the call from my client 2 weeks ago.

This issue wasnt fixed for month now, so i guess it will not fixed soon. I hope this can be helpful.

{% for _p in page.collection %}
  {% set _s = _p.contentMeta.shortcodeMeta.shortcode.section %}
  <h2>{{_s.headline}}</h2>
  .
  ..
  ...
  <p>{{_s.description}}</p>
{% endfor %}

Page structure

01.home
   _first
      default.md
   _spotlight
      _spotlight_item_1
         spi-modular.md
      _spotlight_item_2
         spi-modular.md
      _spotlight_item_3
         spi-modular.md
   sp-modular.md
   _last

The shortcodeobject got the sections of the sp-modular.md and of the first spi-modular.md for every loop.
As is said, the code was working in 2018, when it was delivered to the client.

I like the concept of sections. It's easy to read in the backend (especially when it comes to long text) and it's the common way to put content into grav. Sure u can use the Frontmatter instead, but imo the frontmatter should be used for settings not for content.

Best regards.

k8n added a commit to k8n/grav-plugin-shortcode-core that referenced this issue Feb 8, 2021
A workaround suggested in getgrav#87. Likely addresses getgrav#96 and getgrav#97 as well.
k8n added a commit to k8n/grav-plugin-shortcode-core that referenced this issue Feb 8, 2021
A workaround suggested in getgrav#87. Likely addresses getgrav#96 and getgrav#97 as well.
rhukster pushed a commit that referenced this issue Mar 10, 2021
A workaround suggested in #87. Likely addresses #96 and #97 as well.
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

4 participants