Access section context within shortcode

Hi, I’m trying to iterate through the pages within my section, but to do it within my section’s _index.md. I’m trying to use a shortcode for this, but it seems that the section context within the shortcode is not available.

When I debug with __tera_context I see some information from the section, but the pages variable is always an empty array. This isn’t the case if I debug the same way with the template.

I also tried to pass the section context as an argument to the short code, but it seems like there’s no section context at all within the markdown?

Is the only way to access a section’s context within the template itself?

Rendering of markdown is done before populating the sections so that won’t be possible

I want to do the same.
Here is my try:

<div class="pagesummary"><!-- {{ section.title }} -->
    {% for childpage in section.pages -%}
        <div class="pagesummarytitle"><a href="{{ page.permalink }}">{{ childpage.title }}</a></div>
        <div class="pagesummarydescription">{{ childpage.description }}</div>
        {% for asset in childpage.assets -%}
            {% if asset is matching("[.](jpg|png|svg)$") -%}
                {% set image = resize_image(path=asset, width=240, height=180) -%}
                <div>
                    <a href="{{ get_url(path=asset) }}" target="_blank"><img src="{{ image.url }}" /></a>
                </div>
            {#only first pcture- > break#}
            {%- break -%}
            {% endif -%}
        {% endfor -%}
        {% if childpage.toc -%}
        <div class="pagesummaryheaderlist">            
            {% for tocheader in childpage.toc -%}
            <div class="pagesummaryheaderitem">{{ tocheader.title }}</div>
            {% endfor -%}
        {% endif -%}
        </div>
    {% endfor -%}
</div> <!-- end pagesummary -->

section.title and most all other variables are working, but not section.pages.

From the documentation (Shortcodes | Zola):

You can access a slightly slimmed down version of the corresponding variables in the normal templates. The only things missing are translations, backlinks and pages for sections, as we are still in the middle of editing.

However, I haven’t found a bug entry for this on github. Is this really being worked on?

Hi proofy. From the quote you shared

The only things missing are translations, backlinks and pages for sections, as we are still in the middle of editing.

It says pages are missing, and keats’ comment is why. Hope that helps.

Hi @spence, thanks for the quick reply.
I also understood that this is not possible at the moment.
But is it now generally not possible? Then the documentation should be adapted,
or could this still be implemented, then the appropriate entry is missing in the Github issue.

Maybe I answered a little too quickly. Let me see if I understood your problem and question correctly.

First, let me just confirm that you are talking about accessing the .pages of a section, within a shortcode, right?

If that is the case, then no you can not do it, and it’s not a bug or something waiting to be implemented. I think that’s what you meant by “at this moment” vs “in general”. It’s just not how Zola works.

But is it now generally not possible? Then the documentation should be adapted,

I think where I’m confused is how should the documentation be adapted? To me that’s what it already says, but what should it say, from your pov?

Or maybe I’m mistaking you entirely. Feel free to let me know where I got confused.

It will probably be a misunderstanding on my part because English is not my first language.
I must have misunderstood the subordinate clause (

…, as we are still in the middle of editing.

), namely that the team is currently working on making it possible and not that Zola is working on the wrong place to make it possible.
That’s really hard for me to put into words.
But thank you, I realise now that it’s never going to work. So I have to find another way.

1 Like

Me neither so maybe my text is not clear. I’ll update it.

1 Like

Looks like the docs have already been updated:

The only things missing are translations, backlinks and pages for sections as we are still in the middle of processing.

Is that clearer?

I would simply remove the justification.

The following attributes cannot be used:

  • translations
  • backlinks
  • pages for sections

I agree with proofy, or that if you have to have it in there, the way you said it originally in this thread, I.e.

Rendering of markdown is done before populating the sections so that won’t be possible

is the best path to tidying up the intention in that part of the docs.

However

as we are still in the middle of processing

might be confusing to others. The questions of who “we” or is meant by “middle” or even “processing”. It may not be clear that the “we” is a program, and therefore in the “middle of processing” means the order that things were compiled and therefore what information is available at this step is limited.

So, something like

The following attributes cannot be used:

  • translations
  • backlinks
  • pages for sections

(Note: this is because the rendering of markdown is done before populating the sections)

would be crystal clear, if you wanted to keep the explanation in there.

1 Like

Thanks, I’ll update it tomorrow.

Edit: done

1 Like