In Rails I can do this.

<% content_for :my_block do %>
  <%= <p>line 1</p> %>
<% end %>

<% content_for :my_block do %>
  <%= <p>line 2</p> %>
<% end %>

<% content_for :my_block do %>
  <%= <p>line 2</p> %>
<% end %>


so when I call <%= yield :my_block %>, it will return
<p>line 1</p>
<p>line 2</p>
<p>line 3</p>


The idea here is that it will keep appending to :my_block buffer every
time I print something inside content_for, rather than replacing the
content completely with 'block' tag.

You might suggest calling block.super, but that will only let me
append the content ONE time.

So how do Django people solve this?


This kind of thing is super useful in real world usage.

For example, in the base template I can do this.

<script>
$(function(){
  {% yield :javascript_code %}
  {% endyield %}
});
</script>

Then in my template, I can call {% content_for :javascript_code %}
MULTIPLE times and everything will be wrapped inside ONE single script
tag.

Please show me the Django way.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to