Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template inheritance - example from doc #7

Open
areqq opened this issue May 22, 2024 · 1 comment
Open

Template inheritance - example from doc #7

areqq opened this issue May 22, 2024 · 1 comment

Comments

@areqq
Copy link

areqq commented May 22, 2024

I'm getting to know the project, it looks interesting. I checked one of the examples from the documentation and it didn't work as I expected. the word "Index" was not included in the title. Something is wrong or I don't understand the idea.

https://github.com/emmett-framework/renoir/blob/master/docs/quickstart.md
Template inheritance
output:

<html lang="en">
<head>
    <link rel="stylesheet" href="style.css" />
    <title> - My Webpage</title>
    <style type="text/css">
        .title { color: #336699; }
    </style>
</head>
<body>
    <div id="content">

Index

<h1>Index</h1>
<p class="title">
    Welcome to my awesome homepage.
</p>

    </div>
    <div id="footer">
        Copyright 2020 by you.
    </div>
</body>
</html>
@gi0baro
Copy link
Member

gi0baro commented May 27, 2024

@areqq interesting. Probably something changed in years due to code refactors. I'm gonna check this in the following days, the blocks code might be broken in certain scenarios, or the documentation just need updates; I'm sorry for the bother.

In the meantime, you can use variables instead (this is what I usually do for things like page titles):

layout.html:

{{ common_title = globals().get("common_title", "My Webpage") }}
{{ page_title = globals().get("page_title") }}
{{ title = f"{page_title} - {common_title}" if page_title else common_title }}
<!DOCTYPE html>
<html lang="en">
<head>
    {{ block head }}
    <link rel="stylesheet" href="style.css" />
    <title>{{ =title }}</title>
    {{ end }}
</head>
<body>
    <div id="content">
        {{ block main }}
        {{ include }}
        {{ end }}
    </div>
    <div id="footer">
        {{ block footer }}
        Copyright 2020 by you.
        {{ end }}
    </div>
</body>
</html>

index.html:

{{ page_title = "Index" }}
{{ extend "layout.html" }}

{{ block head }}
    {{ super }}
    <style type="text/css">
        .title { color: #336699; }
    </style>
{{ end }}

<h1>Index</h1>
<p class="title">
    Welcome to my awesome homepage.
</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants