<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Blooki/0.4803" -->
<rss version="2.0">
  <channel>
    <title>Blooki</title>
    <link>http://blooki.org/development/pagination-in-blooki.rs2/</link>
    <description>Grow what you know</description>
    <language>en</language>
    <copyright>Copyright 2010</copyright>
    <lastBuildDate>Sun, 26 Sep 2004 19:11:00 GMT</lastBuildDate>
    <pubDate>Sun, 26 Sep 2004 19:11:00 GMT</pubDate>
    <generator>http://www.blooki.org/</generator>
    <ttl>60</ttl>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs> 


  <item>
    <title>Pagination in Blooki</title>
    <description>&lt;p&gt;&lt;a href="http://weblog.burningbird.net/archives/2004/09/20/some-gratuitous-weblog-software-writing/"&gt;Shelley has been writing&lt;/a&gt; about upcoming Wordpress 1.3 release and one of the features that will be included in the release -- pagination. I got curious about how difficult it would be to add something like this to Blooki. &lt;/p&gt;

&lt;p&gt;First, I added two template variables (&lt;code&gt;entries::prev&lt;/code&gt; and &lt;code&gt;entries::next&lt;/code&gt;) that calculate number of entries to display and &lt;span class="caps"&gt;URL &lt;/span&gt;to use.&lt;/p&gt;

&lt;p&gt;The rest was easy: update template to provide default parameters for number of entries listed and starting position:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar page::entries &amp;lt;&amp;lt;.
  $entries{
    start =&amp;gt; $request{args}{start} || 1,      # start from 1 by default
    display =&amp;gt; $request{args}{display} || 20, # display no more than 20 entries
    header =&amp;gt; $request{isentrypage} ? $entry::prevnext : '', # show entry prev/next
    footer =&amp;gt; q[$entries::prevnext], # show entries prev/next if necessary
  }
.
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This code checks if &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;display&lt;/code&gt; parameters from query string available or uses 1 and 20 by default; it also sets footer to the value of &lt;code&gt;$entries::prevnext&lt;/code&gt; template variable, which is defined as follows:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar entries::prevnext &amp;lt;&amp;lt;.
&amp;lt;div class=&amp;quot;prevnext&amp;quot;&amp;gt;$get{join ' | ', grep {length}
  $entries::prev ? qq[&amp;lt;a href=&amp;quot;$entries::prev{url}&amp;quot;&amp;gt;&amp;amp;lt;&amp;amp;lt; Prev $entries::prev{display}&amp;lt;/a&amp;gt;] : '',
  $entries::next ? qq[&amp;lt;a href=&amp;quot;$entries::next{url}&amp;quot;&amp;gt;Next $entries::next{display} &amp;amp;gt;&amp;amp;gt;&amp;lt;/a&amp;gt;] : '', 
}&amp;lt;/div&amp;gt;
.
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This code generates prev/next links. As parameters are not hardcoded anywhere, users can check &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;display&lt;/code&gt; values as they need (&lt;code&gt;start&lt;/code&gt; can even be negative; in this case it will display entries from the end of the list, just like &lt;code&gt;@foo[-2..-1]&lt;/code&gt; does).&lt;/p&gt;

&lt;p&gt;Excited by the ease of the change I also tried to do prev/next links on entries. This didn't required any coding at all; only a small template change:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar entry::prevnext &amp;lt;&amp;lt;.
&amp;lt;div class=&amp;quot;prevnext&amp;quot;&amp;gt;$get{join ' | ', grep {length}
  $entries{display =&amp;gt; 1, sort =&amp;gt; &amp;quot;-modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;lt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;&amp;amp;lt;&amp;amp;lt; $entry{title}&amp;lt;/a&amp;gt;]},
  $entries{display =&amp;gt; 1, sort =&amp;gt; &amp;quot;+modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;gt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;$entry{title} &amp;amp;gt;&amp;amp;gt;&amp;lt;/a&amp;gt;]},
}&amp;lt;/div&amp;gt;
.
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This code displays prev/next links with titles of entries (if there is previous/next entry). It's also easy to make it display prev/next entries in a particular category, just add a category filter &lt;code&gt;category =&amp;gt; $entry{category}&lt;/code&gt;:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;TemplateVar entry::prevnext &amp;lt;&amp;lt;.
&amp;lt;div class=&amp;quot;prevnext&amp;quot;&amp;gt;$get{join ' | ', grep {length}
  $entries{display =&amp;gt; 1, category =&amp;gt; $entry{category}, sort =&amp;gt; &amp;quot;-modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;lt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;&amp;amp;lt;&amp;amp;lt; $entry{title}&amp;lt;/a&amp;gt;]},
  $entries{display =&amp;gt; 1, category =&amp;gt; $entry{category}, sort =&amp;gt; &amp;quot;+modified_on&amp;quot;, modified_on =&amp;gt; &amp;quot;&amp;gt;$entry{modified_on}&amp;quot;, q[&amp;lt;a href=&amp;quot;$entry::permalink&amp;quot;&amp;gt;$entry{title} &amp;amp;gt;&amp;amp;gt;&amp;lt;/a&amp;gt;]},
}&amp;lt;/div&amp;gt;
.
&lt;/code&gt;&lt;/pre&gt;</description>
    <guid>http://blooki.org/development/pagination-in-blooki.rs2/development/pagination-in-blooki</guid>
    <category>development/</category>
    <pubDate>Sun, 26 Sep 2004 19:11:00 GMT</pubDate>
  </item>


  </channel>
</rss>
