Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Python

Ordering in Django templates

1
2
3
4
5
6
7
# If you don't have access to the queryset to do an order_by, you can still
# do limited ordering in the template with dictsort and dictsortreversed 
# template filters

    {% for s in profile.story_set.all|dictsortreversed:"id" %}
      {{s}}
    {% endfor %}
https://snipt.net/embed/d45c6750167dc53cdb5e66f8c549aa4f/
https://snipt.net/raw/d45c6750167dc53cdb5e66f8c549aa4f/
d45c6750167dc53cdb5e66f8c549aa4f
python
Python
7
2016-12-04T04:52:32
True
False
False
/api/public/snipt/17306/
ordering-in-templates
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># If you don&#39;t have access to the queryset to do an order_by, you can still</span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># do limited ordering in the template with dictsort and dictsortreversed </span> </span><span id="L-3"><a name="L-3"></a><span class="c1"># template filters</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="p">{</span><span class="o">%</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">profile</span><span class="o">.</span><span class="n">story_set</span><span class="o">.</span><span class="n">all</span><span class="o">|</span><span class="n">dictsortreversed</span><span class="p">:</span><span class="s2">&quot;id&quot;</span> <span class="o">%</span><span class="p">}</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">{{</span><span class="n">s</span><span class="p">}}</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">{</span><span class="o">%</span> <span class="n">endfor</span> <span class="o">%</span><span class="p">}</span> </span></pre></div> </td></tr></table>
django, templates

Django/Jinja

In a template, count objects related to an item

{{ task.comment_set.all.count }}
https://snipt.net/embed/13ccd48f3768e08a2d9d1b15e557864d/
https://snipt.net/raw/13ccd48f3768e08a2d9d1b15e557864d/
13ccd48f3768e08a2d9d1b15e557864d
django
Django/Jinja
1
2016-12-03T12:15:37
True
False
False
/api/public/snipt/15099/
in-a-template-count-objects-related-to-an-item
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">{{</span> <span class="nv">task.comment_set.all.count</span> <span class="cp">}}</span><span class="x"></span> </span></pre></div> </td></tr></table>
django, templates

PHP

back to category

1
2
3
4
5
<?php if ($_category = $_product->getCategory()): ?>
<div class="product-back">
    <a href="<?php echo $_category->getUrl(); ?>" onclick="history.back(); return false;" class="form-button-alt" ><?php echo $this->__('Back') ?></a>
</div>
<?php endif;?>
https://snipt.net/embed/0f54745b52df3cc1ecd9838072a6433d/
https://snipt.net/raw/0f54745b52df3cc1ecd9838072a6433d/
0f54745b52df3cc1ecd9838072a6433d
php
PHP
6
2016-12-02T08:33:34
True
False
False
/api/public/snipt/7188/
back-to-category
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span><span class="nv">$_category</span> <span class="o">=</span> <span class="nv">$_product</span><span class="o">-&gt;</span><span class="na">getCategory</span><span class="p">())</span><span class="o">:</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a><span class="x">&lt;div class=&quot;product-back&quot;&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> &lt;a href=&quot;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$_category</span><span class="o">-&gt;</span><span class="na">getUrl</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x">&quot; onclick=&quot;history.back(); return false;&quot; class=&quot;form-button-alt&quot; &gt;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">__</span><span class="p">(</span><span class="s1">&#39;Back&#39;</span><span class="p">)</span> <span class="cp">?&gt;</span><span class="x">&lt;/a&gt;</span> </span><span id="L-4"><a name="L-4"></a><span class="x">&lt;/div&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">&lt;?php</span> <span class="k">endif</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
magento, templates
Copyrighted, illegal, or inappropriate content? Email [email protected].