[Solved]-How do you parse and inject additional nodes in a Jinja extension?
7👍 ✅ templatetags/wrap.py class WrapExtension(jinja2.ext.Extension): tags = set([‘wrap’]) template = None def parse(self, parser): tag = parser.stream.current.value lineno = parser.stream.next().lineno args, kwargs = self.parse_args(parser) body = parser.parse_statements([‘name:end{}’.format(tag)], drop_needle=True) return nodes.CallBlock(self.call_method(‘wrap’, args, kwargs), [], [], body).set_lineno(lineno) def parse_args(self, parser): args = [] kwargs = [] require_comma = False while parser.stream.current.type != ‘block_end’: if require_comma: parser.stream.expect(‘comma’) if … Read more