title: Define variables in template based on user being staff or not
body: <p>I'm trying to display an HTML table of values with about 20 columns  where say staff users see one subset of columns, and non-staff users see another subset of columns.  I may want to define further types of users later.  Now right now I have three static header rows so the template looks like</p>
  <pre><code>&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Col A&lt;/th&gt;
    {% if user.is_staff %}&lt;th&gt;Col B&lt;/th&gt;{% endif %}
    ...
    {% if not user.is_staff %}&lt;th&gt;Col K&lt;/th&gt;{% endif %}
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Col A second header&lt;/td&gt;
    {% if user.is_staff %}&lt;td&gt;Col B second header&lt;/td&gt;{% endif %}
    ...
    {% if not user.is_staff %}&lt;td&gt;Col K second header&lt;/td&gt;{% endif %}&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Col A third header&lt;/td&gt;  ...  &lt;/tr&gt;
  
  {% for obj in object_list %}
  &lt;tr&gt;
    &lt;td&gt;{{ obj.col_a }}&lt;/td&gt;
    {% if user.is_staff %}&lt;td&gt;{{ obj.col_b }}&lt;/td&gt;{% endif %}
    ...
    {% if not user.is_staff %}&lt;td&gt;{{ obj.col_k }}&lt;/td&gt;{% endif %}
  &lt;/tr&gt;
  {% endfor %}&lt;/table&gt;
  </code></pre>
  <p>However, I find non-DRY as every time, if I want to change if a user-type can see a column, I have to change it in 4 places.  Or if I want to define multiple different classes of users, I'd have to have complicated if statements.  I'd prefer something like</p>
  <pre><code> {% if show_col_a %}&lt;td&gt;{{obj.col_a }}&lt;/td&gt;{{% endif %}
  </code></pre>
  <p>Where I can define at the top of the template (or possibly in the view) that user.is_staff can see show_col_a.  Is something like this possible?  I'm using a generic view (object_list).  Maybe modify all users to have attributes user.show_col_a somehow and do {% if user.show_col_a %}?  I'm not sure how to add boolean attributes to users.</p>
  <p>EDIT: May want multiple users with custom views (e.g., staff_view; admin_view, unprivileged, etc.), so if statements would get unwieldy.  A cell's contents is typically more complicated than {{ obj.col_b }}; tried simplifying problem to get to the point.  E.g.:</p>
  <pre><code>&lt;td&gt;{% if obj.custom_address %}
    {{ obj.custom_address.webprint|safe }}
  {% else %}
    {{ obj.business.address.webprint|safe }}
  {% endif %}&lt;/td&gt;
  </code></pre>
  <p>Also while multiple templates would work with a simple switch like:</p>
  <pre><code>{% if user.is_staff %}
     {% include &quot;template_staff.html&quot; %}
  {% else %}{% if user.is_admin %}
     {% include &quot;template_admin.html&quot; %}
  {% else %}
     {% include &quot;template_other.html&quot; %}
  {% endif %}
  {% endif %}
  </code></pre>
  <p>I find its not DRY at all; e.g., every edit to a template has to be replicated in three  template.  I guess I could make a script that read generates the three templates from some super_template outside of django but its getting very inelegant.</p>