Search code examples
lektor

Render a Page object from a template


In a Lektor website, I'm facing the following problem:

  • I have a flowblock called facts with an according template called facts.html
  • in that template, I search for facts to display as follows: {% for fact in site.get('/facts').children %}
  • these children have the model fact imposed on them and there is a corresponding fact.html template that renders them

Now the question is: how do I get to render these child pages inside facts.html?

I know this is possible by transforming the fact.html template into a macro that can be called from facts.html, but I was hoping there would be a more elegant way of achieving the same result.

Is there a render-like method available for Page objects?


Solution

  • I can not quite follow your setup. You said you have a .facts attribute that is of type Flow. However, you perform a query on /facts to get its children which suggests that these are sub-pages and not flow blocks. So.. I am not sure what you try to achieve, but:

    You can have template files for flow-blocks, you just have to place them in e.g., templates/blocks/fact.html. If you do that, you can just print out the flow attribute itself (<div>{{ this.facts }}</div>) and all individual flow-blocks will be drawn with the flowblock template.

    EDIT:

    You asked to display another (full) page template into a flow-block type:

    {% set other = site.get('/projects') %}
    {{ site.env.render_template('facts.html', pad=other.pad, this=other)|safe }}