Skip to content

Commit 0941466

Browse files
committedOct 24, 2016
Expose "data" as "global_data" in templated shortcodes (Fixes #2488)
1 parent 926bcc8 commit 0941466

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed
 

‎CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ New in master
44
Bugfixes
55
--------
66

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

910
Features

‎docs/manual.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,10 @@ In that case, the template engine used will be your theme's and the arguments yo
10861086
as well as the global context from your ``conf.py``, are available to the template you
10871087
are creating.
10881088

1089+
You can use anything defined in your confguration's ``GLOBAL_CONTEXT`` as variables in your
1090+
shortcode template, with a caveat: Because of an unfortunate implementation detail, data is called
1091+
"global_data" when used in a shortcode.
1092+
10891093
The Global Context and Data files
10901094
---------------------------------
10911095

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

1122+
11181123
Redirections
11191124
------------
11201125

‎nikola/nikola.py

+7
Original file line numberDiff line numberDiff line change
@@ -1477,9 +1477,16 @@ def _make_renderfunc(self, t_data, fname=None):
14771477
keyword argument dict and then the latter provides the template
14781478
context.
14791479
1480+
Global context keys are made available as part of the context,
1481+
respecting locale.
1482+
1483+
As a special quirk, the "data" key from global_context is made
1484+
available as "global_data" because of name clobbering.
1485+
14801486
"""
14811487
def render_shortcode(*args, **kw):
14821488
context = self.GLOBAL_CONTEXT.copy()
1489+
context['global_data'] = context['data']
14831490
context.update(kw)
14841491
context['_args'] = args
14851492
context['lang'] = utils.LocaleBorg().current_lang

0 commit comments

Comments
 (0)
Please sign in to comment.