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
{% block <name> required %} #1147
Comments
Should this require output or just that there is some expression present? For example, |
Just that the block is present, it can be empty. The goal is to make the programmer acknowledge that this block is required. If they know better and think it should be empty, then by all means. |
You can archive something similar by capturing the block content using a Nevertheless I think this would be a great addition as the hack above does neither allow empty block nor proper exceptions. |
Some notes from discussion with @amy-lei. A required block must be overridden at some point, but not necessarily the direct child. Basically, if a block has This possibly requires adding some tracking information to the context to know what block is being rendered by what template. Some code will need to be added when compiling the block functions to check the context to see if they are required and raise an error if so. Fairly sure this has to be a runtime error, at compile time we don't know enough information. Open questions that don't have to be solved right now:
|
I think it would be fair to say that the terminal template (the tail, if you prefer) must not have any required blocks, and each required block anywhere in the tree must be implemented by exactly one descendant. This should address both open questions. |
Following David's example, does this mean that if both |
Eh, maybe not. Perhaps the rule should be that at least one descendant must implement it, and the bottom-most implementation wins. That would map most closely to the behavior of non-required blocks. |
Does that seem right? |
Yeah, that's basically what will happen if we don't address them at all right now. If a required block is rendered directly for any reason, it fails. I don't think we should do the "override exactly once" check, if it's possible to do at all. A child of a child could legitimately want to further override a block, such as adding some information then calling |
Thanks Amy! |
This is a feature request for blocks which are required to be implemented by the leaf template. One example of where this would be useful is in title blocks. In the parent template:
And in the child:
If the title block is not present in the latter, an error is rased. If the block has any contents other than whitespace or comments in the former, an error is raised. In effect, this requires all pages to have titles.
The text was updated successfully, but these errors were encountered: