✨ feat(settings): add hierarchy-based setting overrides (#128)
This commit is contained in:
40
templates/macros/settings.html
Normal file
40
templates/macros/settings.html
Normal file
@@ -0,0 +1,40 @@
|
||||
{#
|
||||
Evaluates the priority of a particular setting across different scopes.
|
||||
|
||||
The priority is as follows: page > section > config.
|
||||
|
||||
Parameters:
|
||||
- setting: The name of the setting to evaluate.
|
||||
- page: The page object containing settings.
|
||||
- default_global_value: The setting's default value.
|
||||
#}
|
||||
|
||||
{% macro evaluate_setting_priority(setting, page) %}
|
||||
|
||||
{#- Retrieve last ancestor to determine current section, if applicable -#}
|
||||
{%- if page -%}
|
||||
{%- set last_ancestor = page.ancestors | slice(start=-1) %}
|
||||
{%- set current_section = get_section(path=last_ancestor.0) %}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set priority_order = [
|
||||
page.extra[setting] | default(value=""),
|
||||
current_section.extra[setting] | default(value=""),
|
||||
config.extra[setting] | default(value=default_global_value)
|
||||
] -%}
|
||||
|
||||
{%- set output = "false" -%}
|
||||
|
||||
{%- for value in priority_order -%}
|
||||
{%- if value == true -%}
|
||||
{%- set_global output = "true" -%}
|
||||
{%- break -%}
|
||||
{%- elif value == false -%}
|
||||
{%- set_global output = "false" -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{{- output -}}
|
||||
|
||||
{% endmacro %}
|
Reference in New Issue
Block a user