PacktLib: Smarty PHP Template Programming and Applications

Smarty PHP Template Programming and Applications

Credits

About the Authors

About the Reviewer

Preface

Introduction to Smarty

Templating Systems

A Rough Guide to the Software Design Process

Smarty—The Ultimate Templating System for PHP

Smarty’s Main Features

Smarty Internals

Installing and Configuring Smarty

Upgrading a Smarty Site

Summary

Smarty Site Architecture

Separation of Concerns

Roles Involved in Building and Maintaining a Website

Starting a Smarty Project

Summary

What Designers Need to Know

Development Team Problems: Common Scenarios

Roles of a Template Designer and a Programmer

Definitions and Concepts for Designers

Choosing an Editor for Template Design

Collaborating with Programmers

Summary

Creating a Template

Design Concepts, from HTML to TPL

Introduction to Smarty Variables

Starting Templates

Basic Templating

Templates in the Real World

Summary

Advanced Templating

Smarty under the Hood

Stretch your Imagination with Smarty

Available Modifiers

Combining Modifiers

Configuration Files

Summary

Smarty Functions

Types of Smarty Functions

Functions in Action

Action: Re-using Page Elements with the include Function

Explanation

Inserting Dynamic Content

Passing Variables to Included Templates

Saving Variables in Configuration Files

Creating Configuration Sections for Each Page

Handling Lists in Templates

Removing Extra White Space from Templates

Handling JavaScript Code in Templates

Processing Deeply Nested Arrays

Cycling Through a List of Values

Avoiding Spam Indexers

Form-Related Functions

More Form-Related Functions

Summary

Debugging for Designers

Debugging Smarty Templates

Semantic Errors

Common Smarty Errors

Other Common Smarty Errors

Smarty Debug Console

Summary

Built-in Smarty Variables and Methods

Built-in Smarty Variables

Built-in Smarty Methods

Summary

Caching and Performance

Caching in Smarty

Dynamically Caching Template Sections

Clearing the Cache

Advanced Caching Features

Using Cache Groups

Clearing a Cache Group

Avoiding the Cache

Creating a Custom Cache Handler

Optimizing Smarty Applications

Profiling PHP

Designing Sites for Effective Caching

Tools: ApacheBench (ab)

Tools: Xdebug

Tools: WinCacheGrind

Summary

Extending Smarty with Plug-ins

Finding and Installing Plug-ins

Useful Plug-ins

Writing your own Plug-ins

Plug-in Types

Registering Plug-ins

Example Plug-in: Calendar

Example Plug-in: Auto-link URLs

Summary

Filters

Prefilters

Postfilters

Output Filters

Creating Filters

Registering a Filter at Run Time

Manually Loading a Filter

Automatically Loading a Filter

Filter #1: Remove HTML Comments

Filter #2: Benchmark Information

Filter #3: Compress Output with gzip

Filter #4: Search Engine Highlight

Summary

Internationalization

Translation Infrastructure: Gettext

Configuring PHP with Gettext

Simple PHP Example

Setting Up the Gettext Files

Using Gettext with Smarty

Generating a PO File

Advanced Features of Smarty Gettext

Summary

Index