Page.content not available in content root

Hi,

I’m embarrassed for this beginner question and been struggling for over a day getting nowhere.

I noticed that most of the themes assume the top level content/ is where the blog lives and has pagination but I want the document root to act as a simple landing page and all other items in pages/ should just be things like pages/contact.md, pages/about.md etc (or they can just live in content/about.md for all I care as long as the only place that uses blog logic is content/blog/* (e.g. have blog pagination).

For this I created a local templates/home.html (which I took from the zola-clean-blog theme) with the following content:

{% extends "index.html" %}

{% block header %}
<!-- Page Header -->
<header class="masthead" style="background-image: url('{{ get_url(path="/img/about-bg.jpg")}}')">
  <div class="overlay">
  </div>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-md-10 mx-auto">
        <div class="page-heading">
          <h1>Foo Bar</h1>
          <span class="subheading">Foo bar bla</span>
        </div>
      </div>
    </div>
  </div>
</header>
{% endblock header %}

{% block content %}
<!-- Main Content -->
<div class="container">
  <div class="row">
    <div class="col-lg-8 col-md-10 mx-auto">
      {{ page.content | safe }}
    </div>
  </div>
</div>
{% endblock content %}

I’ve then my content/_index.md which loads it like this:

+++
template = "home.html"
render = true
+++

zola throws an error when trying to render this:

Error: Failed to render section '/home/joachim/src/libreguard/content/_index.md'
Reason: Failed to render 'home.html'
Reason: Variable `page.content` not found in context while rendering 'home.html'

the offending line is {{ page.content | safe }} and I can’t figure out how to have content/index.md rendered using this.

oh and my content/index.md looks like this:

+++
title = "Home"
date = 2020-08-01T19:31:27+02:00
description = "Foobar"
draft = true
toc = false
page_template = "home.html"
+++

hello world from index.md

Originally I tried the after-dark theme to make it behave like this but I noticed that in its documentation it already made clear that it assumed paginate_by = 5 must be set when using this theme. In case anyone has some working examples it would be :chefs kiss:

thanks for any pointers - much appreciated.

cheers

The home page is a section so you need to access section.content

I did try that but when I change my template/home.html to:

{% block content %}
<!-- Main Content -->
<div class="container">
  <div class="row">
    <div class="col-lg-8 col-md-10 mx-auto">
      <!-- throws a wobble for now: -->
      {{ section.content | safe }}
      <!-- end of throws a wobble -->
    </div>
  </div>
</div>
{% endblock content %}

it gives me the same thing:

Error: Failed to render page '/home/joachim/src/libreguard/content/index.md'
Reason: Failed to render 'home.html'
Reason: Variable `section.content` not found in context while rendering 'home.html'

what I did now is add paginate_by = 1 and sort_by = "weight" to content/_index.md:

+++
sort_by = "weight"
#template = "home.html"
page_template = "home.html"
#type = "page"
render = true
paginate_by = 1
+++

and then in content/index.md I just defined a weight (all other posts don’t have a weight):

+++
title = "Home"
date = 2020-08-01T19:31:27+02:00
description = "Some description"
draft = true
toc = false
template = "home.html"
type = "page"
weight = 1
+++

I added some additional macros to make sure things in the top directory do not have “Posted by author on date” and it only shows up for things inside blog/ …

I suppose this isn’t the way of doing things and there is a cleaner approach?

Ah sorry.
You use page_template = "home.html" which means every page below that section will use that template so you can get rid of the template line in your content/index.md.

Since you don’t specify a template for the index page (_index.md), it will use index.html and that template/home.html is used to render a page.

I think there’s a bit of misunderstanding for the home page. The home page is a section, that you can customise by creating content/_index.md if needed like you did. You don’t have a home page.
The homepage is a bit special and have its own template but nothing crazy. Have you seen https://www.getzola.org/documentation/getting-started/overview/ ?