Smarty PHP Template Programming and Applications

Hasin Hayder, Joao Prado Maia, Lucian Gheorghe

eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
$12.00 save 50%!
Print book: $39.99
$35.99 save 10%!
Print + eBook bundle: $63.98
Includes free access to the book on PacktLib
$39.59 save 38%!
Free Shipping! UK, US, Europe and selected countries in Asia.
This book can also be purchased from:
Overview
Table of Contents
The Author
Reviews
Downloads
  • Bring the benefits of Smarty to your PHP programming
  • Give your designers the power to modify content and layout without PHP programming
  • Produce code that is easier to debug, maintain, and modify
  • Useful for both Smarty developers and users

Book Details

Language : English
Paperback : 256 pages [ 235mm x 191mm ]
Release Date : April 2006
ISBN : 190481140X
ISBN 13 : 978-1-904811-40-4
Author(s) : Hasin Hayder, Joao Prado Maia, Lucian Gheorghe
Topics and Technologies : All Books, Open Source, PHP, Web Development


Table of Contents

Preface
Chapter 1: Introduction to Smarty
Chapter 2: Smarty Site Architecture
Chapter 3: What Designers Need to Know
Chapter 4: Creating a Template
Chapter 5: Advanced Templating
Chapter 6: Smarty Functions
Chapter 7: Debugging for Designers
Chapter 8: Built-in Smarty Variables and Methods
Chapter 9: Caching and Performance
Chapter 10: Extending Smarty with Plug-ins
Chapter 11: Filters
Chapter 12: Internationalization
Index
  • Chapter 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
      • Plugins
      • 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
  • Chapter 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
  • Chapter 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
  • Chapter 4: Creating a Template
    • Design Concepts, from HTML to TPL
    • Introduction to Smarty Variables
    • Starting Templates
      • Nonassociative Array
      • Associative Array
      • Passing Arrays to Smarty Templates and Manipulating Them
    • Basic Templating
      • Logical Conditions
      • Loops
        • section
        • foreach
    • Templates in the Real World
      • Calendar
      • Database Report
      • Data Input Forms
      • Email Newsletter
      • Running PHP Code Inside your Templates
    • Summary
  • Chapter 5: Advanced Templating
    • Smarty under the Hood
      • Compile Steps
      • Prefilters and Postfilters
      • What is a Smarty Modifier?
    • Stretch your Imagination with Smarty
      • Student Transcript
      • Photo Gallery
    • Available Modifiers
      • capitalize
      • count_characters
      • cat
      • count_paragraphs
      • 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
  • Chapter 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
  • Chapter 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
    • 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
  • Chapter 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
    • Creating a Custom Cache Handler
    • Optimizing Smarty Applications
    • Profiling PHP
    • Designing Sites for Effective Caching
      • The LastModified and ETag Headers
      • The Expires Header
      • The CacheControl Header
  • Tools: ApacheBench (ab)
  • Tools: Xdebug
  • Tools: WinCacheGrind
  • Summary
  • Chapter 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
  • Chapter 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
  • Chapter 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

Hasin Hayder

Hasin Hayder graduated in Civil Engineering from the Rajshahi University of Engineering and Technology (RUET) in Bangladesh. He is a Zend-certified Engineer and expert in developing localized applications. He is currently working as a Technical Director in Trippert Labs and managing the local branch in Bangladesh. Beside his full time job, Hasin writes his blog at http://hasin.wordpress.com, writes article in different websites and maintains his open source framework Orchid at http://orchid.phpxperts.net. Hasin lives in Bangladesh with his wife Ayesha and his son, Afif.


Joao Prado Maia

João Prado Maia is Lead Software Developer with Alert Logic, Inc. and was previously with MySQL AB as the lead developer behind Eventum, an issue tracking system, and MySQL Network, a subscription product for everything related to MySQL services. He has been working with PHP, Smarty, and PEAR for several years, and maintains phpbrasil.com, one of the most popular PHP-related community sites in Brazil. He is also interested in fostering a community of PHP developers in Houston by organizing the Houston PHP Users Group at http://www.houstonphp.org.


Lucian Gheorghe

Lucian Gheorghe has just joined the Global NOC of Interoute, Europe's largest voice and data network provider. Before Interoute, he was working as a senior network engineer for Globtel Internet, a significant Internet and Telephony Services Provider to the Romanian market He has been working with Linux for more than 8 years putting a strong accent on security for protecting vital data from hackers and ensuring good quality services for internet customers. Moving to VoIP services he had to focus even more on security as sensitive billing data is most often stored on servers with public IP addresses. He has been studying QoS implementations on Linux to build different types of services for IP customers and also to deliver good quality for them and for VoIP over the public internet. Lucian has also been programming with Perl, PHP and Smarty for over 5 years mostly developing in-house management interfaces for IP and VoIP services.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Find your book in our support section to find errata and to download code samples.

What you will learn from this book

This book is a comprehensive guide to all aspects of using Smarty. It will help you to:

  • Install and configure Smarty on your Web server
  • Understand how Smarty affects your web site architecture, and build site foundations that make the most of what Smarty offers
  • Designers will learn to work with templates that contain variables and logic, to modify layouts or content of Smarty web sites
  • See how Smarty caching can improve the performance of your sites
  • Develop custom Smarty functions and plug-ins to incorporate into your templates

Special Offers

PacktLib gives you access to this and 600+ other titles with an annual or monthly subscription.

Annual subscription:

$220.00 per annum

Monthly subscription:

$21.99 per month

Buy 2 eBooks
and Get 50% Off
+
Buy Smarty PHP Template Programming and Applications with PHP 5 CMS Framework Development - 2nd Edition and get 50% off both the eBooks.
Just add both the eBooks to your shopping cart and enter sm5ebk in the 'Enter Promotion Code' field. Click 'Add Promotion Code' and the discount will be applied.
View Best Selling eBook offers

In Detail

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.

Visit the Free Online Edition for Smarty PHP Template Programming and Applications and learn more about the book and discover what each chapter from this book has in store.

You can now download "Smarty Cheat Sheet" for free: http://smartybook.packtpub.com/

Approach

Using a step-by-step approach based on realistic examples, the expert authors show you how to use Smarty in your own PHP development.

Who this book is for

This book is written for PHP developers who want to use Smarty templates in their development, and for designers who are working with PHP developers who are using Smarty.

Are there no books available that are right for you at the moment? How about signing up to our newsletter to keep up to date?
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Sort A-Z