Django - wrap child blocks with loop in template -


I am quite new to Django, and although I know that you have several blocks with the same name in a template Can not be (without some hacking), I am looking for a way to do the following:

  for #parent template {% block% item} & lt; Div class = "outer" & gt; & Lt; Div class = "inner" & gt; {% Block item%} {% endblock%} & lt; / Div & gt; & Lt; / Div & gt; {% Endfor%} #child template {% "parent_template"%} extends {% block item%} & lt; P & gt; Fu goes here & lt; / P & gt; {% Endblock%} {% Block Item%} & lt; P & gt; The bar goes here & lt; / P & gt; {% Endblock%}  

And so on, where the result will look something like this:

  & lt; Div class = "outer" & gt; & Lt; Div class = "inner" & gt; & Lt; P & gt; Fu goes here & lt; / P & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "external" & gt; & Lt; Div class = "inner" & gt; & Lt; P & gt; The bar goes here & lt; / P & gt; & Lt; / Div & gt; & Lt; / Div & gt; ... etc ...  

This is not like 'especially above', but this is a general idea.

Hope that makes sense.

I think you have solved the problem so far, but if someone else has the same thing There is a need to do, I believe that the easiest (and possibly only) way is to remove those parts that you have to include in a different template and include a loop in it. For example, in your case I Something like this:

  # collection.html {% for item in block}% {element = item =} {% Endfor%} # item.html & lt; Div class = "external" & gt; & Lt; Div class = "inner" & gt; {{Element}} & lt; / Div & gt; & Lt; / Div & gt; The major drawbacks here are the performance (which may or may not be a problem) and the fact is that you may have to expand two different templates when you have an internal bits Changes are required because you have to change whatever gets included in the collection. Of course, you can take care of this by using a variable to make sure that the items in the item that you want to include, such as:  
  {% item_template element = item %}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -