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

Preface

Smarty is a powerful templating tool that can breathe new life into PHP programming, and solve many of the difficulties PHP programmers face on non-trivial projects.

This book will take you through the Smarty basics step by step, showing you how to realize the benefits from this product. But this is no “hello world” tutorial; the book also covers advanced Smarty topics crucial to large-scale web development: performance, internationalization, customization, and so on.

Smarty is an established engine with a proven track record for making development and design easier and more elegant. Whether you’re just starting with Smarty, or are looking for extra insights on advanced features, this book will help you.

What This Book Covers

The first two chapters are an introduction to Smarty. The remaining chapters of the book are divided into two main sections. Chapters 3-7 deal with Smarty template design, and are aimed primarily at designers. The later chapters get more technical, showing how programmers can work with Smarty and PHP to create complex, interactive and high performance applications. Here’s what each chapter covers:

Chapter 1 will ease you into the world of Smarty. Starting with an overview of what templating systems are and why you use them, it goes on to consider Smarty specifically. Once that’s covered, you’ll see how to install Smarty so you’re ready to begin your Smarty development.

Chapter 2 discusses how Smarty can make projects easier for programmers and designers, reduce the time taken on programming and maintenance, and bring harmony to the fraught relationship between designers and programmers. You’ll then see how to start your first n-tier Smarty project.

Chapter 3 is a designer’s overview of Smarty, explaining the key concepts and how designers can create versatile and attractive templates and layouts.

Chapter 4 looks at templates in detail, showing how values pass into templates and how to use them in applications such as calendars, database-backed reports, email newsletters and more.

Chapter 5 covers more advanced ways to work with templates, including how to play with variables right in the template using modifiers.

Chapter 6 delves into the programming side of Smarty. There are many powerful functions that designers can use to make Smarty development easier and more productive. This chapter introduces the most useful of these, and provides practical examples of functions in action.

With all the added power in the designer’s hands, there are bound to be mistakes occasionally.

Chapter 7 will introduce you to methods for debugging your Smarty templates, so that you’ll be able to find why the wrong values are being displayed, or that pesky extra <td> tag is ruining your layout.

Chapter 8 starts with more technical aspects of Smarty. You will see how built-in variables and methods bring added functionality to your PHP code, with very little extra work.

Chapter 9 looks at how Smarty can make the code itself faster. This in-depth look at Smarty’s caching and performance features, and how to optimize your code for them, will enable you to write very scalable and fast applications with Smarty.

Chapter 10 pushes Smarty even further, showing how to extend its capabilities with downloadable plug-ins, and even showing how to write your own.

Chapter 11 takes a detailed look at filters, which are a special kind of plug-in.

Chapter 12 concludes the book with a look at how to make your website available in different locales and languages using Smarty’s internationalization features.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

There are three styles for code. Code words in text are shown as follows: “We can include other contexts through the use of the include directive.”

A block of code will be set as follows:

<?php
include_once(‘libs/Smarty.class.php’);
$smarty = new Smarty;
$smarty->caching = 1;
$smarty->display(‘example2.tpl’);
?>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

<?php
include_once(‘libs/Smarty.class.php’);
$smarty = new Smarty;
$smarty->caching = 1;
$smarty->display(‘example2.tpl’);
?>

Any command-line input and output is written as follows:

$ xgettext -o smartybook.po -n *.php

New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: “clicking the Next button moves you to the next screen”.

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader Feedback

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer Support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the Example Code for the Book

Visit http://www.packtpub.com/support, and select this book from the list of titles to download any example code or extra resources for this book. The files available for download will then be displayed.

Note

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the Submit Errata link, and entering the details of your errata. Once your errata have been verified, your submission will be accepted and the errata added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Questions

You can contact us at if you are having a problem with some aspect of the book, and we will do our best to address it.