{# 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, section="", default_global_value="") %} {%- if section -%} {%- set current_section = section -%} {%- elif page -%} {#- Retrieve last ancestor to determine current section, if applicable -#} {%- 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="") ] -%} {%- set output = default_global_value -%} {%- for value in priority_order -%} {%- if value != "" -%} {%- set_global output = value -%} {%- break -%} {%- endif -%} {%- endfor -%} {{- output -}} {% endmacro %}