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

Templates need a variable that could be “section” or “page” #687

Open
chris-morgan opened this issue May 17, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@chris-morgan
Copy link

commented May 17, 2019

I find that I need this in templates, e.g. in the base template:

{% set section_or_page = section | default(value = page) -%}

That way I can do things like active page highlighting in top nav:

<a href="/help/" {% if section_or_page.path is starting_with('help/') %}class="is-selected"{% endif %}">Help</a>

Something to think about. As you see, there is a workaround, but it’s not exactly elegant. At the least, it should be documented.

@Keats

This comment has been minimized.

Copy link
Collaborator

commented May 17, 2019

For that specific usecase, all templates get current_path so you don't need to access the section/page variable for that.
Do you have an example of a common variable needed apart from the path?

@chris-morgan

This comment has been minimized.

Copy link
Author

commented May 17, 2019

OK, that was indeed a bad example; I’d forgotten about current_path.

description and extra.* for various things like meta tags in the base template, and other properties in certain other templates: basically I find that in various places I don’t want most of the distinction between sections and pages, and so want to be able to reuse template portions for both sections and pages.

Still, I think the path is the most probable case where people in general will want to do this, so it’d probably be acceptable to just document the workaround for when you wish to treat section and page alike in a template.

@Walther

This comment has been minimized.

Copy link

commented May 26, 2019

Cross-referencing a related discussion thread here: https://zola.discourse.group/t/idea-better-page-metadata-for-published-pages/111

@Keats Keats added enhancement and removed enhancement labels May 27, 2019

@Keats

This comment has been minimized.

Copy link
Collaborator

commented May 30, 2019

Any good name that could represent both?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.