Article

eZ publish: PHP's Killer App - Parts 1-3

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Next

Template Alert

Now as I mentioned in earlier rant, PHP is a templating system. Unfortunately eZ systems opted to create their own templating system -- and their own markup language for it. There's even an entire templating class, and if you look in menubox.tpl you'll find code like:

$t->set_var( "sitedesign", $GlobalSiteDesign );

...where a PHP variable is mapped to a template variable. This constitutes a significant processing overhead, and slows down your Web pages -- why eZ systems chose not to use the same approach as frame.php I can't say. A large amount of processing could have been avoided had the system used include(), or opened the file with eval(). Hopefully this is something that'll change with the release of eZ publish 3.0, to either utilise PHP's native ability to template, or even use XML and XSLT to allow eZ publish to deliver multiple interfaces like XHTML, WML, PDF etc. However, right now we'll have to work with the existing templating system.

Take a look at the start of menubox.tpl and you'll find:

<tr>          
<td colspan="2" class="menuhead">{intl-title}</td>          
</tr>

The template variable {intl-title} lives in [ezpublish_root]/ezarticle/user/intl/en_GB/menubox.php.ini so let's update that first:

[strings]          
title=Inside...          
latest=Recent          
...          
front_page=Home

I'm going to take a liberty now, and update the entire menubox.tpl in one step:

<table class="menu">          
<tr>          
<td colspan="2" class="menutitle">{intl-title}</td>          
</tr>          
<tr>          
<td class="menuitem">          
<a href="{www_dir}{index}/article/frontpage/1">{intl-front_page}</a>          
</td>          
</tr>          
<tr>          
<td class="menuitem">          
<a href="{www_dir}{index}/article/archive/0/">{intl-latest}</a>          
</td>          
</tr>          
<tr>          
<td class="menuitem">          
<a href="{www_dir}{index}/article/author/list/">{intl-authors}</a>          
</td>          
</tr>          
<tr>          
<td class="menuitem">          
<a href="{www_dir}{index}/article/sitemap/">{intl-site_map}</a>          
</td>          
</tr>          
</table>          
         
<br />          
         
<table class="menu">          
<tr>          
<td colspan="2" class="menutitle">{intl-categories}</td>          
</tr>          
<!-- BEGIN article_category_tpl -->          
<tr>          
<td class="menuitem">          
<a href="{www_dir}{index}/article/archive/{articlecategory_id}/          
{section_id}">          
{articlecategory_title}</a>          
</td>          
</tr>          
<!-- END article_category_tpl -->          
</table>

Two things are worth noting in the above template.

First of all, I've added a "1" at the end of the following link, so that when visitors click on "Home", they'll end up in the correct section. This is not strictly necessary, but it gives you an idea of how to use sections should you need to.

<a href="{www_dir}{index}/article/frontpage/1">{intl-front_page}</a>

Also, the HTML comments (shown again below) are used by eZ publish to insert loops into templates -- this row will appear more than once, depending on how many categories of article you create from the eZ publish administration interface.

<!-- BEGIN article_category_tpl -->          
...HTML here...          
<!-- END article_category_tpl -->

Now that you have some idea of how templates work and how to apply them, I'm going to pull that "Here's one I prepared earlier..." trick they use in all the cookery programs...

To cut a long story short, I've updated the following template files:

  • articleheaderlist.tpl
  • articlelist.tpl
  • articlestatic.tpl
  • articleprint.tpl
  • articleview.tpl
  • authorlist.tpl
  • authorview.tpl
  • frontpage.tpl
  • mailtofriend.tpl
  • menubox.tpl
  • search.tpl
  • sitemap.tpl

Also in [ezpublish_root]/ezarticle/user/intl/en_GB/menubox.php.ini I updated:

  • articlelist.ini.php
  • frontpage.ini.php
  • nubox.tpl

All these and main frame.php you'll find in a ZIP file below (I wouldn't want you to have to do any really hard work, after all)...

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links