title: Django truncate blog summary puzzle
body: <p>I'm building a blog in Django and realized something about my templates: The blog home page can display all the individual posts using the same format as a single blog, the only difference being that the text will be truncated for summary.</p>
  
  <p>So what I did was define a template for displaying a blog that I'd include in the home page template:</p>
  
  <pre><code>{# blog/post_snippet.html #}
  {% block content %}
      &lt;h1&gt; {{ post.title }} &lt;/h1&gt;
      {% if post.author %}
          &lt;h4&gt;By {{ post.author.short_name }}&lt;/h4&gt;
      {% endif %}
  
      {% if post.date_published %}
          &lt;span&gt;On {{ post.date_published }}&lt;/span&gt;
      {% endif %}
      &lt;p&gt; {{ post.text | safe }} &lt;/p&gt;
  {% endblock %}
  </code></pre>
  
  <p>And this gets used inside a for loop in the "all posts" page:</p>
  
  <pre><code>{% block content %}
      {% for post in posts %}
          {% include 'blog/post_snippet.html' %}
      {% endfor %}
  {% endblock %}
  </code></pre>
  
  <p>The problem now is, when displaying all the posts, how do I tell the template system to truncate the blog text? One solution is to duplicate the template code but I don't want to do that. I also thought of inheriting, but my templates already inherit from a base template, plus I think inheriting will immediately insert all the content and so I won't be able to control the block placement??</p>
  
  <p>I'm quite confused, actually. What's the best practice here?</p>