<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Passing Curiosity: Posts tagged language</title>
    <link href="https://passingcuriosity.com/tags/language/language.xml" rel="self" />
    <link href="https://passingcuriosity.com" />
    <id>https://passingcuriosity.com/tags/language/language.xml</id>
    <author>
        <name>Thomas Sutton</name>
        
        <email>me@thomas-sutton.id.au</email>
        
    </author>
    <updated>2008-07-22T00:00:00Z</updated>
    <entry>
    <title>The SPIP Template Language</title>
    <link href="https://passingcuriosity.com/2008/spip-template-languag/" />
    <id>https://passingcuriosity.com/2008/spip-template-languag/</id>
    <published>2008-07-22T00:00:00Z</published>
    <updated>2008-07-22T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>SPIP, like many content management systems, provides a templating facility
based on the idea of loops. A template is a mixture of static content – HTML
tags, for instance – dynamic content placeholders – that stand for things
like “the title”, “the body”, “the date of publication”, etc.– and loops –
which determine what and how much is displayed. Unlike some CMS’, SPIP uses a
rather sophisticated language for its template system rather than just
providing a library of PHP functions that can be called. The placeholders in
SPIP templates look like <code>#VALUE</code> and can be supplied with arguments
<code>#VALUE{argument}</code>, modified using filters <code>#VALUE|uppercase</code> (which can also
take arguments <code>#VALUE|foo{bar}</code>), and bracketed with conditional content
which is output only when the tag has a non-empty <code>[&lt;li&gt;(#VALUE)&lt;/li&gt;]</code>. I
can’t remember if it’s necessary, but I always wrap any tag with a parameter
or filter with brackets, just in case.</p>
<p>The loops look somewhat stranger with a pseudo HTML tag format. In general
each loop has :</p>
<ul>
<li><p>a name;</p></li>
<li><p>a type (of things it iterates over, pretty much 1-to-1 with database
tables);</p></li>
<li><p>some of criteria (determine <em>which</em> things to loop over);</p></li>
<li><p>a body; <em>and</em></p></li>
<li><p>optionally, some conditional content.</p></li>
</ul>
<p>An example will help illustrate:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode html"><code class="sourceCode html"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>    <span class="dt">&lt;</span><span class="kw">B_aloop</span><span class="dt">&gt;</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;</span><span class="kw">ol</span><span class="dt">&gt;</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;</span><span class="kw">BOUCLE_aloop</span><span class="ot">(ARTICLES)</span><span class="er">{</span><span class="ot">id_article IN </span><span class="er">1,2,3,5,7,11}</span><span class="dt">&gt;</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>            <span class="dt">&lt;</span><span class="kw">li</span><span class="dt">&gt;</span>This article was published on: [(#DATE|affdate('Y'))].<span class="dt">&lt;/</span><span class="kw">li</span><span class="dt">&gt;</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;/</span><span class="kw">BOUCLE_aloop</span><span class="dt">&gt;</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;/</span><span class="kw">ol</span><span class="dt">&gt;</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>    <span class="dt">&lt;/</span><span class="kw">B_aloop</span><span class="dt">&gt;</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;</span><span class="kw">p</span><span class="dt">&gt;</span>There are no matching articles.<span class="dt">&lt;/</span><span class="kw">p</span><span class="dt">&gt;</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>    <span class="er">&lt;</span>//B_aloop&gt;</span></code></pre></div>
<p>Upon seeing this code SPIP does the following (along with some other stuff in
the database and caching layers). It retrieves all of the articles with an ID
of 1, 2, 3, 5, 7, or 11. If there <em>are</em> some articles it outputs <code>&lt;ol&gt;</code>,
followed by a line like <code>&lt;li&gt;This article was published on: 2008&lt;/li&gt;</code> for
each article, followed by <code>&lt;/ol&gt;</code>. If there were no matching articles, then it
instead outputs <code>&lt;p&gt;There are no matching articles.&lt;/p&gt;</code>.</p>
<p>There are a few more details (the name of the loop above is “_aloop” not
“aloop”, you can reach out of a loop to one that contains it like so
<code>#outerloop:VALUE</code>…), but that’s basically it. For more details about the
specific loops, criteria, tags, and filters available in SPIP you can see the
<a href="http://www.spip.net/@?lang=en">SPIP Glossary</a>, though do note that SPIP, like
pretty much all open source software, has documentation that is a little bit
patchy in places, especially in English.</p>
<p>In my next SPIP post, I’ll describe ways to extend SPIP with your own tags and
filters and alter on, I’ll explore modifying and even creating our own custom
loops.</p>]]></summary>
</entry>

</feed>
