Skip to content

Commit

Permalink
Expose "data" as "global_data" in templated shortcodes (Fixes #2488)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Oct 24, 2016
1 parent 926bcc8 commit 0941466
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions docs/manual.txt
Expand Up @@ -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
---------------------------------

Expand Down Expand Up @@ -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
------------

Expand Down
7 changes: 7 additions & 0 deletions nikola/nikola.py
Expand Up @@ -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
Expand Down

0 comments on commit 0941466

Please sign in to comment.