python - Jinja2 Extension Tag within another Tag -


I'm tring to do something

  {% mytag country "Italy" year "2014"%} workday {% holyday}} no working day {% endmytag%}   

But the holy postal tag is optional. It should also work:

  {% mytag country "Italy" year "2014"%} workday {% endmytag%}   

I wrote the code < / P>

  class matag extension (extension): tag = set (['mytag']) def __init __ (self, environment): super (translation extension, itself) .__ init __ (environment) def Parse (self, parser): lineno = parser.stream.next (). Lineno if parser.stream.skip_if ('name: country'): country = parser.parse_primary () other: country = nodes.Const (None) parser.stream.skip_if if ('name: year'): year = parser. Parse_primy () Other: Year = Nodes Consest (none) Argances = [country, year] # body1 = parser.parse_statements (['name: holyday']) # Not working :) body = parser.parse_statements (['name: endmytag'], drop_needle = true ) Return nodes. Callblock (self.call_method ('_help', RGR), [], [], body) .set_lineno (lineno) def _helper (self, country, year, collar): etc ....   a  if else endif , but I did not find the source  if  tag's code (if it exists as an extension in the form of extension)  

How can I do this? Obviously in my _helper I need both first and second branch because there exists that I show to whom.

OK, here is an answer, this is not right and probably is not the best, but it Something is there. parser.parse_statements (['name: endimate tag', 'name: perthay'], drop_needal = true) if not then parser.stream.current.test (' block_end '): body.extend ([' name: endmytag '], drop_needle = true) args = [country, year, nodes. .data]), # I do not like this line :) :) Return nodes Call Block (AutoCall_method ('_helper', args), [], [], body) .set_lineno (lineno) ...

_helper will receive the third parameter (a list) and select Return the first or the second element of this list.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -