Book Image

Smarty PHP Template Programming and Applications

By : Hasin Hayder, Joao Prado Maia, Lucian Gheorghe
Book Image

Smarty PHP Template Programming and Applications

By: Hasin Hayder, Joao Prado Maia, Lucian Gheorghe

Overview of this book

<p>Smarty is a templating engine for PHP. Designers who are used to working with HTML files can work with Smarty templates, which are HTML files with simple tags while programmers work with the underlying PHP code. The Smarty engine brings the code and templates together. The result of all this is that designers can concentrate on designing, programmers can concentrate on programming, and they don't need to get in each others way so much. Even if you are developing a site on your own, Smarty is a powerful way to make your code clearer to you and others, as well as easier to debug and modify later.</p>
Table of Contents (18 chapters)
Smarty PHP Template Programming and Applications
Credits
About the Authors
About the Reviewer
Preface
Index

Example Plug-in: Calendar


Our first example plug-in will be used to dynamically build a table containing the days of a particular month, just like what you would see if you opened your existing calendar application, like Microsoft Outlook, iCal, or Evolution. You should be able to specify what month and year you want from the template file, but if those parameters are not used, the current month and year will be used instead.

After running our calendar plug-in we expect the following output:

If possible the plug-in should be as simple to use as calling the function like:

{calendar month=4 year=2005}

As described before, if the month and year parameters are not provided, the current date will be used instead.

So to get that far, let’s first create the PHP script and Smarty template that will be used to call our plug-in.

Create a new PHP script called example_calendar.php and put the following content in it:

<?php
include_once(‘libs/Smarty.class.php’);
$smarty = new Smarty;

$smarty->display...