templatel icon indicating copy to clipboard operation
templatel copied to clipboard

Variable not recognized inside base template

Open markokocic opened this issue 4 years ago • 1 comments

Not sure if this is weblorg or templatel issue, feel free to close and move to weblorg if this is not the right place.

I have base.html template and home.html template that extends base.

The route is defined like this:

(weblorg-route
 ;; route for rendering index page of the blog
 :site blog
 :name "home"
 :input-pattern "posts/*.org"
 :input-aggregate #'weblorg-input-aggregate-all-desc
 :template "home.html"
 :output "output/index.html"
 :url "/")

home.html just lists posts and their descriptions in the main area.

Inside a base.html I tried to define a sidebar that will contain just links to the posts, by referencing the same post variable, like this:

          {% for post in posts %}
            <li><a href="{{ post.url }}">{{ post.title }}</a></li>
          {% endfor %}

When generating blog, I get the following error: Template Error: base.html: Variable `posts' not declared

Is there a way in templatel and weblorg to achieve something like this? How can the variable be visible inside base template? Or it needs to be defined globally inside a weblorg-site?

One workaround could be to define an empty sidebar block in base.html, and to override that block inside every template that extends base, but that would be a repetition that I'd like to avoid if possible.

Or maybe wait until include is implemented, but then again, including would still need its route to set variables before including it as a html output.

markokocic avatar Mar 17 '21 13:03 markokocic

Sorry, haven't had time to look into this, but I think you're right that it'd be a templatel issue. Thank you for taking the time to file the issue 🙇🏾

clarete avatar Apr 10 '21 04:04 clarete