@@ -1452,7 +1452,14 @@ def render_shortcode(*args, **kw):
1452
1452
return render_shortcode
1453
1453
1454
1454
def _register_templated_shortcodes (self ):
1455
- """Register shortcodes provided by templates in shortcodes/ folders."""
1455
+ """Register shortcodes based on templates.
1456
+
1457
+ This will register a shortcode for any template found in shortcode/
1458
+ and a generic "template" shortcode which will consider the content
1459
+ in the shortcode as a template in itself."""
1460
+
1461
+ self .register_shortcode ('template' , self ._template_shortcode_handler )
1462
+
1456
1463
builtin_sc_dir = resource_filename (
1457
1464
'nikola' ,
1458
1465
os .path .join ('data' , 'shortcodes' , utils .get_template_engine (self .THEMES )))
@@ -1470,6 +1477,20 @@ def _register_templated_shortcodes(self):
1470
1477
self .register_shortcode (name , self ._make_renderfunc (
1471
1478
fd .read (), os .path .join (sc_dir , fname )))
1472
1479
1480
+ def _template_shortcode_handler (self , * args , ** kw ):
1481
+ t_data = kw .pop ('data' , '' )
1482
+ context = self .GLOBAL_CONTEXT .copy ()
1483
+ context .update (kw )
1484
+ context ['_args' ] = args
1485
+ context ['lang' ] = utils .LocaleBorg ().current_lang
1486
+ for k in self ._GLOBAL_CONTEXT_TRANSLATABLE :
1487
+ context [k ] = context [k ](context ['lang' ])
1488
+ output = self .template_system .render_template_to_string (t_data , context )
1489
+ # XXX FIXME: we have no standard way to get dependency information from
1490
+ # a template that's not a file
1491
+ dependencies = []
1492
+ return output , dependencies
1493
+
1473
1494
def register_shortcode (self , name , f ):
1474
1495
"""Register function f to handle shortcode "name"."""
1475
1496
if name in self .shortcode_registry :
0 commit comments