How do I render a page as part of another page

I tried searching around and maybe I’m not using the right words, but I couldn’t exactly find the functinality I wanted.

I am adapting a blog template and want to do the following: the complete and rendered HTML to be included in the index page of that section (aka, the blog articles are sequentially rendered in the index, instead of just a summary).

Is this possible? The paginator picks up the different articles but in the for loop page.content only gets me the content of that block, not the entire rendered page.

Can this be done in Zola and if so, how?

What’s “the entire rendered page”? If it’s missing stuff like tags, title… then you would need to edit the templates.

Namely, whatever template is being used to render the entire content (each article by itself) would need to be introduced in whatever template is using the paginator (presumably section.html).

This is what my for look currently looks like in the template:

{% for page in paginator.pages | reverse %}
      <section class="post animated fadeInDown">
        <div class="post-title">
                <h3><a href="{{ page.permalink }}">{{ page.title }}</a></h3>
        </div>
        <div class="post-content">
              <p>
                {{ page.content }}
              </p>
        </div>
        <div class="post-footer">
              <div class="meta">
                <div class="info">
                  {% if page.date %}
                    <i class="far fa-sun"></i>
                    <span class="date">
                      {{ page.date | date(format=trans(key="date_format", lang=lang)) }}
                    </span>
                  {% endif %}
                  {% if page.taxonomies.tags %}
                    <i class="fas fa-tags"></i>
                    {% for tag in page.taxonomies.tags %}
                      <a class="tag" href="{{ get_taxonomy_url(kind="tags", name=tag, lang=page.lang) | safe }}">&nbsp;{{tag}}</a>
                    {% endfor %}
                  {% endif %}
                </div>
              </div>
        </div>
      </section>
    {% endfor %}

I have multiple pages in this section that I want to include in full in the main page. I am not sure how I can include that template in the main page and still keep the article rendering like all the separate frontmatter for those articles.

So instead of just including the content as it does now, I want it to render the template of that article and include that html in the section where it now says {{ page.content }} in the for-each.

I’m gonna guess that this is something Zola can’t do right now, because of the silence?

you might be thinking of `tera macros

resuable elements that could be used in various places.

they are placed under temples > macro folder.

I don’t think there’s support for what you want, in exactly the way you describe, sorry. As mentioned elsewhere macros are probably the most idiomatic way of doing this and what I’d recommend.

However, if you still want to do it, I think that there might be a way to emulate the same behavior that you were describing, although I haven’t tried it myself and I think that it might not work with template inheritance.

Let’s say you have a page called page1.md as follows:

+++
template = "example.html"
+++
this is an example

So that page above has a template called example.html. If you wanted to “render” the html of page1.md but in the code you showed above, you may be able to do so by using {% include "example.html" %}. What’s going to happen is whatever variables you have in the outer template will be made available to example.html when include is used. So, if you have a variable called page for example, and that’s what example.html normally uses, then you can probably emulate what you wanted.

Where I think this may be a problem for you is if have any kind of inheritance in your page’s template. I don’t think using includes and using extends really mix very well.

Again, I haven’t tested this myself, but I think it’s possible. Hope that helps!

Isn’t it enough to replace the {{ page.content }} line with the actual template that renders the page?

For example, I render a list of posts with this macro. As you can see, it shows some metadata (tags, date) and the summary.

If I wanted to “embed” the actual post content on the listing, I would modify this “list all posts” template so that, for each post, it renders whatever is visible on the actual post page (date, headers… whatever).

How would I make it render everything for every page in the page collection? Including the front matter of those pages?

The same way it’s being rendered in the individual article’s template: by accessing the proper variables (e.g. accessing post.date from my macro link).

I tried that, but then I get an error accessing page.extra variables to get my custom frontmatter.

Caveat: I didn’t use the macro, just adjusted the template of my index page.

I don’t know what to tell you. I just tested it, just in case, and I was able to access extra variables as expected.

Perhaps your Tera logic needs fixing? If not all posts have a particular extra variable, you need to first check whether it exists.

For example, this will fail if a single post doesn’t have the foo variable:

Post's foo: {{ post.extra.foo }}

This will work:

{% if post.extra.foo %}
Post's foo: {{ post.extra.foo }}
{% endif %}

Create a MACRO from your current PAGE template and then use it in the SECTION template. replacing {{ page.content}} with the call to that new macro.

You do need to make some templates.