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

Pass default template values for Page, Collection #236

Open
kjaymiller opened this issue Jul 25, 2023 · 5 comments
Open

Pass default template values for Page, Collection #236

kjaymiller opened this issue Jul 25, 2023 · 5 comments
Milestone

Comments

@kjaymiller
Copy link
Collaborator

There is only a few default template paths to be expected (explicit is better than...)

Some themes probably have a desired usage and forcing the user to memorize each one (especially when there are multiple themes being used).

Suggestion

ThemeManager could have attributes for
- default_page_template,
- default_collection_template,
- default_archive_template

Each of these would be str|None and only apply if the attribute is supplied

@kjaymiller
Copy link
Collaborator Author

More info:
so if the list of templates are

{
"test.html": "Test1",
"test.html": "Test2",
"test.html": "Test3",
}

The result when calling test.html will be "Test1"
If someone is making a template they have two choices. override or workaround
Then the user has the same two choices
the order of preference is User --> Templates --> Render Engine

This change would have some values defined by default which would reduce the need to manually define your template all the time

It would also make it so that if you use that object, you can rely on a default template path. If the system defines a default the user and theme maker both know what the default is and can always default their path to it.

@kjaymiller
Copy link
Collaborator Author

This is connected to #228

@tataraba
Copy link

Okay, so we would be adding those attributes to the ThemeManager class like so:

class ThemeManager:

    engine: Environment
    output_path: str = "output"
    static_paths: set[str|pathlib.Path] = {"static"}
    default_page_template: str | None = None
    default_collection_template: str | None = None
    default_archive_template:  str | None = None

The end goal would be that if a template path is provided for, say, default_page_template--this would mean that the a user would not need to pass in a template value within the Page class? However, if the user does pass a template in through the Page class, it would take precedence over the default?

Would we then control the loaders from the register_themes method in ThemeManager?

@kjaymiller
Copy link
Collaborator Author

Yes one of the things that running register_themes does is add the themes loader to the Environment. It also installs all the filters from the theme.

@kjaymiller kjaymiller changed the title Pass default values for Page, Collection Pass default template values for Page, Collection Dec 14, 2023
@kjaymiller
Copy link
Collaborator Author

kjaymiller commented Dec 14, 2023

@tataraba -

I'm a little torn on this as I'm trying to figure out if it's better to ask the user to specify.

Assumption:

  • Basic page's default template should be page.html which is a built-in template.

WHY THIS ASSUMPTION IS BAD:

  • Some pages don't need templates and are just generated content.

  • RSSFeeds are page objects if there was a default template. This could cause issues.

  • If you wanted to generate a report using render_engine (not sure why you would yet but you could), You may or may not want a template.

  • If there is a plugin for htmx and you're rendering output from some subpage, you likely don't want that page to be templated

Also currently with render_content the check is (in order):
If there is a template attribute you render from the template and pass in your globals, kwargs, etc.
if no template attribute is given then you render the content (arguably you should also be able to check for data and render it).

Finally if none of those things exist... raise ValueError

I think it may be better to instruct users with good documentation and error handling how to ensure that their pages load as expected.

@kjaymiller kjaymiller added this to the Backlog milestone Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants