Skip to content
Permalink
Browse files
Expose "data" as "global_data" in templated shortcodes (Fixes #2488)
  • Loading branch information
ralsina committed Oct 24, 2016
1 parent 926bcc8 commit 09414662ea5dac16137df62febc388c06c71c856
Showing with 13 additions and 0 deletions.
  1. +1 −0 CHANGES.txt
  2. +5 −0 docs/manual.txt
  3. +7 −0 nikola/nikola.py
@@ -4,6 +4,7 @@ New in master
Bugfixes
--------

* Make "data" from global context available to templated shortcodes (Issue #2488)
* Don't crash if plugins is a file (Issue #2539)

Features
@@ -1086,6 +1086,10 @@ In that case, the template engine used will be your theme's and the arguments yo
as well as the global context from your ``conf.py``, are available to the template you
are creating.

You can use anything defined in your confguration's ``GLOBAL_CONTEXT`` as variables in your
shortcode template, with a caveat: Because of an unfortunate implementation detail, data is called
"global_data" when used in a shortcode.

The Global Context and Data files
---------------------------------

@@ -1115,6 +1119,7 @@ JSON/YAML/TOML files and Nikola generates a large page with data from all data
files. (This is especially useful with some automatic rebuild feature, like
those documented in `Deployment`_)


Redirections
------------

@@ -1477,9 +1477,16 @@ def _make_renderfunc(self, t_data, fname=None):
keyword argument dict and then the latter provides the template
context.
Global context keys are made available as part of the context,
respecting locale.
As a special quirk, the "data" key from global_context is made
available as "global_data" because of name clobbering.
"""
def render_shortcode(*args, **kw):
context = self.GLOBAL_CONTEXT.copy()
context['global_data'] = context['data']
context.update(kw)
context['_args'] = args
context['lang'] = utils.LocaleBorg().current_lang

0 comments on commit 0941466

Please sign in to comment.