The Blogs Page: The index/blogs view script
Sunday, February 28, 2010
As with the other pages, the view script for the blogs page makes use of jQuery UI tabs. The special feature of this page compared to the others is that the number of tabs is dependent on the number of blogs in the database.
The script contains the following code:
$this->tabPane( 'tabs', $this->render('index/blogs/our-blogs.phtml'), array('title' => 'Our Blogs') ); foreach ($this->blogs as $blog) { $this->tabPane( 'tabs', $this->partial('index/blogs/blog-partial.phtml', array( 'name' => $blog->name, 'href' => $blog->href, 'description' => $blog->description, 'id' => $blog->id ) ), array('title' => $blog->name) ); } echo $this->tabContainer('tabs');
The page makes use of the partial view helper to render the markup for each blog page’s tab. The partial helper takes two parameters; the first indicates the file containing the partial view script, the second the variable parameters used to fill out this script. The partial view script used here contains the following:
<h1><a href="<?php echo $this->href; ?>"> <?php echo $this->name; ?></a></h1> <p> <strong>URL: </strong> <a href="<?php echo $this->href; ?>" rel="nofollow"> <?php echo $this->href; ?></a> </p> <p> <strong>Description:</strong> <?php echo $this->description; ?> </p> <?php echo $this->ajaxFeedDigest($this->id) . PHP_EOL;
The parameters passed to the partial view script are the blog name and description, its URL, and its ID. The last is passed to the AjaxFeedDigest view helper.
We shall look at the implementation of the AjaxFeedDigest view helper in the next post. It is used to render a list of the most recent five posts on the specified blog, using the blog’s feed to fetch the information. The decision to use an AJAX approach to rendering this list was because sometime it can take a little time to fetch this information. If the site had to wait for it before rendering the rest of the page, the user can often be faced with an unacceptable wait staring at a blank browser tab. However, if the rest of the page is rendered first, then the user can at least view that; the information for each blog feed can then be filled in as soon as it is available.


