Add class-level customization and visibility control for TemplateHooks.
Review Request #14556 — Created Aug. 6, 2025 and submitted
TemplateHookhas always requiredname,template_name,apply_to,
andextra_contextto be passed into__init__(), even in a subclass.
This makes usage a bit verbose.This change adds new class-level control of these options. Now, a
subclass can define these as class attributes and they'll be used if the
caller doesn't override any of them with a parameter.Subclasses can also opt out of rendering by overriding
should_render(), which means they no longer need to handle this in a
template.
Unit tests pass.
Tested this with the banner component work in Review Board, utilizing
the new features.
| Summary | ID | 
|---|---|
| 33373351585be57972d5c74fb9cee401d563f884 | 
| Description | From | Last Updated | 
|---|---|---|
| Testing done? |  | |
| Indentation doesn't match between TemplateHook and class MyTemplateHook |  | |
| typo: facored -> factored |  | |
| This list is missing the closing ] |  maubin | |
| We don't actually enforce that apply_to has been provided like we do with the name attribute. If apply_to hasn't been … |  maubin | |
| Same comment here, we're not actually enforcing that extra_content must be set or passed as an argument. |  maubin | |
| Given that this is typed as Mapping, we should probably assert isinstance(extra_context, Mapping) |  | |
| Should be 5.3, not 7.1 |  | 
- Change Summary:
- 
    Fixed typos and indentation in docs. 
- Testing Done:
- 
    + Unit tests pass. + + Tested this with the banner component work in Review Board, utilizing + the new features. 
- Commits:
- 
    Summary ID 254835faee3415a0fb103ec5dcb04f6f6eae11c5 ca415aff511e4a551ac5009105d9d86e585b0843 
Checks run (2 succeeded)
 
   - 
 
- 
 
 
- 
 We don't actually enforce that apply_tohas been provided like we do with thenameattribute. Ifapply_tohasn't been passed as an argument and hasn't been set as an attribute we default it to an empty list.
- 
 Same comment here, we're not actually enforcing that extra_contentmust be set or passed as an argument.
- Change Summary:
- 
    Fixed a typo in the docs, and some misworded parts about parameter/attribute fallbacks. 
- Commits:
- 
    Summary ID ca415aff511e4a551ac5009105d9d86e585b0843 080257623a3e3ebccdbb7a62fa21bf69afe232fd 
