

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Helpers &mdash; django-ttag v1.0 documentation</title>
    <link rel="stylesheet" href="_static/agogo.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '1.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="django-ttag v1.0 documentation" href="index.html" />
    <link rel="next" title="Reference" href="reference.html" />
    <link rel="prev" title="Usage" href="usage.html" /> 
  </head>
  <body>
    <div class="header-wrapper">
      <div class="header">
        <h1><a href="index.html">django-ttag v1.0 documentation</a></h1>
        <div class="rel">
          <a href="usage.html" title="Usage"
             accesskey="P">previous</a> |
          <a href="reference.html" title="Reference"
             accesskey="N">next</a> |
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a>
        </div>
       </div>
    </div>

    <div class="content-wrapper">
      <div class="content">
        <div class="document">
            
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="helpers">
<h1>Helpers<a class="headerlink" href="#helpers" title="Permalink to this headline">¶</a></h1>
<div class="section" id="astag">
<h2>AsTag<a class="headerlink" href="#astag" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="ttag.helpers.AsTag">
<em class="property">class </em><tt class="descclassname">ttag.helpers.</tt><tt class="descname">AsTag</tt><a class="headerlink" href="#ttag.helpers.AsTag" title="Permalink to this definition">¶</a></dt>
<dd><p>Assists with the common case of tags which want to add something to the
context.</p>
<p>For example, if you wanted a tag which would add a QuerySet containing a
user&#8217;s friends to the context (<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">get_friends</span> <span class="pre">user</span> <span class="pre">as</span> <span class="pre">friends</span> <span class="pre">%}</span></tt>):</p>
<div class="highlight-python"><pre>class GetName(ttag.helpers.AsTag)
    user = ttag.Arg()

    def output(self, data, context):
        return data['user'].friends_set.all()</pre>
</div>
<p>Some additional customization attributes to those which are provided in the
standard <tt class="docutils literal"><span class="pre">Tag</span></tt>&#8216;s <a class="reference internal" href="reference.html#ttag.Tag.Meta" title="ttag.Tag.Meta"><tt class="xref py py-attr docutils literal"><span class="pre">Meta</span></tt></a> class are available:</p>
<dl class="class">
<dt id="ttag.helpers.AsTag.Meta">
<em class="property">class </em><tt class="descname">Meta</tt><a class="headerlink" href="#ttag.helpers.AsTag.Meta" title="Permalink to this definition">¶</a></dt>
<dd><dl class="attribute">
<dt id="ttag.helpers.AsTag.Meta.as_name">
<tt class="descname">as_name</tt><a class="headerlink" href="#ttag.helpers.AsTag.Meta.as_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Use some other argument name rather than the default of <tt class="docutils literal"><span class="pre">as</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="ttag.helpers.AsTag.Meta.as_required">
<tt class="descname">as_required</tt><a class="headerlink" href="#ttag.helpers.AsTag.Meta.as_required" title="Permalink to this definition">¶</a></dt>
<dd><p>Set whether or not <tt class="docutils literal"><span class="pre">as</span> <span class="pre">varname</span></tt> argument is required
(defaults to <tt class="xref docutils literal"><span class="pre">True</span></tt>).</p>
</dd></dl>

</dd></dl>

<p>Two additional methods of interest are <tt class="docutils literal"><span class="pre">as_value</span></tt>, which allows you to
more completely customise output.</p>
<dl class="method">
<dt id="ttag.helpers.as_value">
<tt class="descclassname">ttag.helpers.</tt><tt class="descname">as_value</tt><big>(</big><em>self</em>, <em>data</em>, <em>context</em><big>)</big><a class="headerlink" href="#ttag.helpers.as_value" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the value you want to put into the context variable.
By default, returns the value of <a class="reference internal" href="reference.html#ttag.Tag.output" title="ttag.Tag.output"><tt class="xref py py-meth docutils literal"><span class="pre">output()</span></tt></a>.</p>
</dd></dl>

<dl class="method">
<dt id="ttag.helpers.as_output">
<tt class="descclassname">ttag.helpers.</tt><tt class="descname">as_output</tt><big>(</big><em>self</em>, <em>data</em>, <em>context</em><big>)</big><a class="headerlink" href="#ttag.helpers.as_output" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the data you want to render when <tt class="docutils literal"><span class="pre">as</span> <span class="pre">varname</span></tt> is used.
Defaults to <tt class="docutils literal"><span class="pre">''</span></tt>.</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
        </div>
        <div class="sidebar">
          <h3>Table Of Contents</h3>
          <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="usage.html">Usage</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Helpers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#astag">AsTag</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="reference.html">Reference</a></li>
</ul>

          <h3 style="margin-top: 1.5em;">Search</h3>
          <form class="search" action="search.html" method="get">
            <input type="text" name="q" size="18" />
            <input type="submit" value="Go" />
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>
          <p class="searchtip" style="font-size: 90%">
            Enter search terms or a module, class or function name.
          </p>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

    <div class="footer-wrapper">
      <div class="footer">
        <div class="left">
          <a href="usage.html" title="Usage"
             >previous</a> |
          <a href="reference.html" title="Reference"
             >next</a> |
          <a href="genindex.html" title="General Index"
             >index</a>
            <br/>
            <a href="_sources/helpers.txt"
               rel="nofollow">Show Source</a>
        </div>

        <div class="right">
          
    <div class="footer">
        &copy; Copyright 2010, Lincoln Loop.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
        </div>
        <div class="clearer"></div>
      </div>
    </div>

  </body>
</html>