Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Lucian Gheorghe, Joao Prado Maia, Hasin Hayder
Smarty PHP Template Programming and Applications
Smarty PHP Template Programming and Applications
Table of Contents
Smarty PHP Template Programming and Applications
Credits
About the Authors
About the Reviewer
Preface
What This Book Covers
Conventions
Reader Feedback
Customer Support
Downloading the Example Code for the Book
Errata
Questions
1. Introduction to Smarty
Templating Systems
Why Use a Templating System?
The Smartness of Smarty
Smarty Alternatives
A Rough Guide to the Software Design Process
Working in Teams: Layers and Separation of Concerns
Smarty—The Ultimate Templating System for PHP
Is Smarty Fast?
Is Smarty Secure?
Smarty’s Main Features
Variable Modifiers
Template Functions
Debugging
Plug-ins
Filters
Smarty Internals
Installing and Configuring Smarty
Step 1: Obtaining Smarty
Step 2: Configure PHP to Find the Smarty Libraries
On Windows
On Linux
An Alternative to Step 2: Using Smarty without Having Full Access to the System
Step 3: Set Up Smarty for Your Application
Step 4: Verifying the Installation
Smarty Development Versions on CVS
Upgrading a Smarty Site
Summary
2. Smarty Site Architecture
Separation of Concerns
What Does Concern Mean?
A Problem-Solving Perspective
Cross-cutting Concerns
Roles Involved in Building and Maintaining a Website
Starting a Smarty Project
Directory Structure
Securing our Smarty Project
The Data Access Layer
How it Works
The Business Logic Layer
How it Works
The Presentation Layer
How it Works
The Result
Summary
3. What Designers Need to Know
Development Team Problems: Common Scenarios
Roles of a Template Designer and a Programmer
Definitions and Concepts for Designers
Concept of Reusability and Components
Splitting into Components
How to Design Table-less Layouts?
Handy Built-in Tags
Choosing an Editor for Template Design
Collaborating with Programmers
Summary
4. Creating a Template
Design Concepts, from HTML to TPL
Introduction to Smarty Variables
Starting Templates
Non-associative Array
Associative Array
Passing Arrays to Smarty Templates and Manipulating Them
Basic Templating
Logical Conditions
Loops
section
index
first
iteration
total
loop
foreach
Templates in the Real World
Calendar
Database Report
Data Input Forms
Email Newsletter
Running PHP Code Inside your Templates
Summary
5. Advanced Templating
Smarty under the Hood
Compile Steps
Prefilters and Postfilters
What is a Smarty Modifier?
Stretch your Imagination with Smarty
Student Transcript
Table Name: Grade
Table Name: Courses
Photo Gallery
Available Modifiers
capitalize
count_characters
cat
count_paragraphs
count_sentences
count_words
date_format
default
escape
indent
lower
upper
nl2br
regex_replace
replace
spacify
string_format
strip
strip_tags
truncate
wordwrap
Combining Modifiers
Configuration Files
Summary
6. 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
7. Debugging for Designers
Debugging Smarty Templates
Semantic Errors
Common Smarty Errors
Other Common Smarty Errors
Smarty Debug Console
Summary
8. Built-in Smarty Variables and Methods
Built-in Smarty Variables
$template_dir
$compile_dir
$config_dir
$plugins_dir
$debugging
$error_reporting
$debug_tpl
$debugging_ctrl
$compile_check
$force_compile
$caching
$cache_dir
$cache_lifetime
$cache_modified_check
$php_handling
$security
$secure_dir
$security_settings
$trusted_dir
$left_delimiter
$right_delimiter
$request_vars_order
$request_use_auto_globals
$compile_id
$use_sub_dirs
$default_modifiers
$default_resource_type
$cache_handler_func
$autoload_filters
$config_overwrite
$config_booleanize
$config_read_hidden
$config_fix_newlines
$default_template_handler_func
$compiler_file
$compiler_class
$config_class
Handy Built-in Smarty Variables Table
Built-in Smarty Methods
assign
assign_by_ref
Example: Working of assign and assign_by_ref
How it Works
The Result
append
append_by_ref
clear_assign
register_function
unregister_function
register_object
unregister_object
register_block
unregister_block
register_compiler_function
unregister_compiler_function
register_modifier
unregister_modifier
register_resource
unregister_resource
register_prefilter
unregister_prefilter
register_postfilter
unregister_postfilter
register_outputfilter
unregister_outputfilter
load_filter
clear_cache
clear_all_cache
is_cached
clear_all_assign
clear_compiled_tpl
template_exists
get_template_vars
get_config_vars
trigger_error
display
fetch
config_load
get_registered_object
clear_config
Summary
9. 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
Disabling a Template Cache
Using {insert} to Avoid Caching
Creating a Custom Plug-in to Avoid Caching on Portions of a Template
Creating a Custom Cache Handler
Optimizing Smarty Applications
Profiling PHP
Designing Sites for Effective Caching
The Last-Modified and ETag Headers
The Expires Header
The Cache-Control Header
Tools: ApacheBench (ab)
Tools: Xdebug
Tools: WinCacheGrind
Summary
10. Extending Smarty with Plug-ins
Finding and Installing Plug-ins
Useful Plug-ins
HTML List Plug-in
File Size Format Plug-in
Google Highlight Plug-in
Writing your own Plug-ins
Plug-in Types
Functions
Modifiers
Block Functions
Compiler Functions
Prefilters, Postfilters, and Output Filters
Resources
Inserts
Registering Plug-ins
Example Plug-in: Calendar
Example Plug-in: Auto-link URLs
Summary
11. 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
12. 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
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Table of Contents
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset