Skip to content

Instantly share code, notes, and snippets.

@oampo
Created January 16, 2013 12:13
Show Gist options
  • Save oampo/4546750 to your computer and use it in GitHub Desktop.
Save oampo/4546750 to your computer and use it in GitHub Desktop.
Template globals in Wok
from template_globals import template_globals
hooks = {
"page.template.pre" : [template_globals]
}
import yaml
import collections
with open("globals.yaml") as f:
extra_template_variables = yaml.load(f.read())
def template_globals(page, template_variables):
recursive_dict_update(template_variables, extra_template_variables)
def recursive_dict_update(dictionary, other):
for key, value in other.iteritems():
if isinstance(value, collections.Mapping):
r = recursive_dict_update(dictionary.get(key, {}), value)
dictionary[key] = r
else:
dictionary[key] = other[key]
return dictionary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment