Discussion:
[bottlepy] Macros for Bottle's STPL
'Vinay Sajip' via bottlepy
2017-12-29 13:52:27 UTC
Permalink
I want to be able to reuse functions which produce output in Bottle
templates, using STPL - functionality which is referred to as "macros" in
e.g. Jinja2. I couldn't see any discussion on this forum other than this
old post from 2012
<https://groups.google.com/forum/#!searchin/bottlepy/macro%7Csort:date/bottlepy/ESV9AQ91ftA/pl-5wUI55ykJ>.
I am not sure the approach described there is still valid (given that the
*include* implementation has since changed). To give an example of what I'm
talking about: imagine a template full of definitions, such as funcs.tpl
given here as an example with just one function:

% def cdnlink(lib, version, type):
% if type == 'css':<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/{{ lib }}/{{ version }}/css/{{ lib }}.min.css" />\\
% else:<script src="https://cdnjs.cloudflare.com/ajax/libs/{{ lib }}/{{ version }}/js/{{ lib }}.min.js"></script>\\
% end
% end


I'd like to be able to use functions defined like in the following example,
page.tpl:

% macrodefs('funcs.tpl', 'macros')
<html>
<head>
{{! macros.cdnlink('select2', '4.0.5', 'css') }}
</head>
<body>
{{! macros.cdnlink('select2', '4.0.5', 'js') }}
</body>
</html>


such that when the page.tpl template is rendered, I can get output like this:

<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css" />
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js"></script>
</body></html>

Is there such functionality available, and if not, would there be any interest in adding it, if that could be done in a simple way? I have an idea that it could be done fairly simply and would be willing to come up with a PR if there is interest in merging this type of feature.

Regards,

Vinay Sajip
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...