Smarty PHP Template Programming and Applications


Smarty PHP Template Programming and Applications
eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
$12.00
save 50%!
Print + free eBook + free PacktLib access to the book: $63.98    Print cover: $39.99
$39.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • 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 : 9781904811404
Author(s) : Hasin Hayder, Joao Prado Maia, Lucian Gheorghe
Topics and Technologies : All Books, Web Development, 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.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 21 submitted: last submission 08 Apr 2014

Errata type: Future reference | Page number: 0 | Errata date: 05 Sep 06

The code could use some performance improvement.

 

Errata type: Typo | Page number: 17 | Errata date: 18 Feb 08

Paragraph 2 under Headline "Step 3:...": should be 'properties' not 'proprieties'

 

Errata type: Technical Issue | Page number: 17 | Errata date: 18 Feb 08

Missing apostrophe (') on line 3 at the end of the define procedure define('SMARTY_DIR', 'C:\apache\htdocs\mycode\libs\); Should be define('SMARTY_DIR', 'C:\apache\htdocs\mycode\libs\');

 

Errata type: Code | Page number: 17 | Errata date: 03 Apr 09

Missing apostrophe (') on line 3 at the end of the define procedure.

 

Errata type: Typo | Page number: 17 | Errata date: 03 Apr 09

Paragraph 2 (first line) under Heading "Step 3:...": It should be "properties" and not "proprieties".

 

Errata type: Code | Page number: 17 | Errata date: 03 Apr 09

chmod 770 /www/hdocs/templates_c should be chmod 770 /www/htdocs/templates_c

 

Errata type: Code | Page number: 24 | Errata date: 01 Sep 06

The code for books.php in Chapter 2 was missing in the code download package. The concerned code has been included in the package and re-uploaded.

 

Errata type: Future Reference | Page number: 26 | Errata date: 04 Sep 06

Variable declaration as 'public', 'private', & 'protected' are not supported by PHP 4.x.x only supported in PHP 5.x.x.

 

Errata type: PHP 4 support | Page number: 26 | Errata date: 04 Sep 06

Variable declarations such as 'public', 'private', & 'protected' are not supported by PHP 4.x.x only supported in PHP 5.x.x. Some examples will need slight modification to work with PHP 4.

 

Errata type: Code | Page number: 42 | Errata date: 03 Apr 09

#body { left: 210px; ... } should be: #body { margin-left: 210px; ... }.

 

Errata type: Missing $ sign | Page number: 51 | Errata date: 31 Aug 06

<td>{student.email}</td> should have a $ sign just after the first curly bracket.

 

Errata type: Typo | Page number: 52 | Errata date: 20 Jul 07

Replace "$smarty = new Smarty ();" with "$smarty = new smarty ();".

 

Errata type: Typo | Page number: 54 | Errata date: 05 Sep 06

In the section on Associative Array, the array declaration misses a comma after "roll"=>12 and a closing parenthesis and comma after "roll"=>18, respectively.

 

Errata type: Indenting | Page number: 54 | Errata date: 05 Sep 06

IThe section on associative array has a slight indenting problem in the array declaration.

 

Errata type: Small syntax errors| Page number: 54 | Errata date: 06 Sep 06

There is a comma missing after "roll"=>12)
Closing parenthesis missing after "roll"=>18

 

Errata type: Typo| Page number: 58 | Errata date: 03 Apr 09

"sample_section.tpl" should be "sample_section2.tpl"

 

Errata type: Code| Page number: 60 | Errata date: 15 Nov 06

The code of sample_section2.tpl: sample_section2.tpl {foreach item=book loop=$books} Title: {$book.title} Price: {$book.price} Author: {$book.authors} {/section} shoulde be : {foreach item=book from=$books} Title: {$book.title} Price: {$book.price} Author: {$book.authors} {/foreach}

 

Errata type: Technical Issue| Page number: 60 | Errata date: 15 Feb 08

{if $smarty.section.section_name.first}

This is Heading

{else} do what ever you want {endif} the {endif} tag should be replaced by {/if}

 

 

Errata type: Code problem | Page number: 68 | Errata date: 27 Jul 06

The survey.tpl file has been updated with the required changes.

 

Errata type: Technical Issue | Page number: 73| Errata date: 15 Feb 08

Tmail($user, "Newsletter", $out, $headers); Should be mail($user, "Newsletter", $output, $headers);

 

Errata type: Code | Page number: 58

As mentioned on page number 58, the code is given as {section} The code should be like {/section} Slash should be added before section

Sample chapters

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

Frequently bought together

Smarty PHP Template Programming and Applications +    Advanced Penetration Testing for Highly-Secured Environments: The Ultimate Security Guide =
50% Off
the second eBook
Price for both: $42.60

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

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

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.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
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