0%

Book Description

Key Features

  • 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 Description

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.

What you will learn

  • 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

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.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Smarty PHP Template Programming and Applications
    1. Table of Contents
    2. Smarty PHP Template Programming and Applications
    3. Credits
    4. About the Authors
    5. About the Reviewer
    6. Preface
      1. What This Book Covers
      2. Conventions
      3. Reader Feedback
      4. Customer Support
        1. Downloading the Example Code for the Book
        2. Errata
        3. Questions
    7. 1. Introduction to Smarty
      1. Templating Systems
        1. Why Use a Templating System?
        2. The Smartness of Smarty
        3. Smarty Alternatives
      2. A Rough Guide to the Software Design Process
        1. Working in Teams: Layers and Separation of Concerns
      3. Smarty—The Ultimate Templating System for PHP
        1. Is Smarty Fast?
        2. Is Smarty Secure?
      4. Smarty’s Main Features
        1. Variable Modifiers
        2. Template Functions
        3. Debugging
        4. Plug-ins
        5. Filters
      5. Smarty Internals
      6. Installing and Configuring Smarty
        1. Step 1: Obtaining Smarty
        2. Step 2: Configure PHP to Find the Smarty Libraries
          1. On Windows
          2. On Linux
        3. An Alternative to Step 2: Using Smarty without Having Full Access to the System
        4. Step 3: Set Up Smarty for Your Application
        5. Step 4: Verifying the Installation
        6. Smarty Development Versions on CVS
      7. Upgrading a Smarty Site
      8. Summary
    8. 2. Smarty Site Architecture
      1. Separation of Concerns
        1. What Does Concern Mean?
        2. A Problem-Solving Perspective
        3. Cross-cutting Concerns
      2. Roles Involved in Building and Maintaining a Website
      3. Starting a Smarty Project
        1. Directory Structure
        2. Securing our Smarty Project
        3. The Data Access Layer
          1. How it Works
        4. The Business Logic Layer
          1. How it Works
        5. The Presentation Layer
          1. How it Works
        6. The Result
      4. Summary
    9. 3. What Designers Need to Know
      1. Development Team Problems: Common Scenarios
      2. Roles of a Template Designer and a Programmer
      3. Definitions and Concepts for Designers
        1. Concept of Reusability and Components
        2. Splitting into Components
        3. How to Design Table-less Layouts?
        4. Handy Built-in Tags
      4. Choosing an Editor for Template Design
      5. Collaborating with Programmers
      6. Summary
    10. 4. Creating a Template
      1. Design Concepts, from HTML to TPL
      2. Introduction to Smarty Variables
      3. Starting Templates
        1. Non-associative Array
        2. Associative Array
        3. Passing Arrays to Smarty Templates and Manipulating Them
      4. Basic Templating
        1. Logical Conditions
        2. Loops
          1. section
            1. index
            2. first
            3. iteration
            4. total
            5. loop
          2. foreach
      5. Templates in the Real World
        1. Calendar
          1. Database Report
        2. Data Input Forms
        3. Email Newsletter
        4. Running PHP Code Inside your Templates
      6. Summary
    11. 5. Advanced Templating
      1. Smarty under the Hood
        1. Compile Steps
        2. Prefilters and Postfilters
        3. What is a Smarty Modifier?
      2. Stretch your Imagination with Smarty
        1. Student Transcript
          1. Table Name: Grade
          2. Table Name: Courses
        2. Photo Gallery
      3. Available Modifiers
        1. capitalize
        2. count_characters
        3. cat
        4. count_paragraphs
        5. count_sentences
        6. count_words
        7. date_format
        8. default
        9. escape
        10. indent
        11. lower
        12. upper
        13. nl2br
        14. regex_replace
        15. replace
        16. spacify
        17. string_format
        18. strip
        19. strip_tags
        20. truncate
        21. wordwrap
      4. Combining Modifiers
      5. Configuration Files
      6. Summary
    12. 6. Smarty Functions
      1. Types of Smarty Functions
      2. Functions in Action
      3. Action: Re-using Page Elements with the include Function
      4. Explanation
      5. Inserting Dynamic Content
      6. Passing Variables to Included Templates
      7. Saving Variables in Configuration Files
      8. Creating Configuration Sections for Each Page
      9. Handling Lists in Templates
      10. Removing Extra White Space from Templates
      11. Handling JavaScript Code in Templates
      12. Processing Deeply Nested Arrays
      13. Cycling Through a List of Values
      14. Avoiding Spam Indexers
      15. Form-Related Functions
      16. More Form-Related Functions
      17. Summary
    13. 7. Debugging for Designers
      1. Debugging Smarty Templates
      2. Semantic Errors
      3. Common Smarty Errors
      4. Other Common Smarty Errors
      5. Smarty Debug Console
      6. Summary
    14. 8. Built-in Smarty Variables and Methods
      1. Built-in Smarty Variables
        1. $template_dir
        2. $compile_dir
        3. $config_dir
        4. $plugins_dir
        5. $debugging
        6. $error_reporting
        7. $debug_tpl
        8. $debugging_ctrl
        9. $compile_check
        10. $force_compile
        11. $caching
        12. $cache_dir
        13. $cache_lifetime
        14. $cache_modified_check
        15. $php_handling
        16. $security
        17. $secure_dir
        18. $security_settings
        19. $trusted_dir
        20. $left_delimiter
        21. $right_delimiter
        22. $request_vars_order
        23. $request_use_auto_globals
        24. $compile_id
        25. $use_sub_dirs
        26. $default_modifiers
        27. $default_resource_type
        28. $cache_handler_func
        29. $autoload_filters
        30. $config_overwrite
        31. $config_booleanize
        32. $config_read_hidden
        33. $config_fix_newlines
        34. $default_template_handler_func
        35. $compiler_file
        36. $compiler_class
        37. $config_class
        38. Handy Built-in Smarty Variables Table
      2. Built-in Smarty Methods
        1. assign
        2. assign_by_ref
        3. Example: Working of assign and assign_by_ref
          1. How it Works
          2. The Result
        4. append
        5. append_by_ref
        6. clear_assign
        7. register_function
        8. unregister_function
        9. register_object
        10. unregister_object
        11. register_block
        12. unregister_block
        13. register_compiler_function
        14. unregister_compiler_function
        15. register_modifier
        16. unregister_modifier
        17. register_resource
        18. unregister_resource
        19. register_prefilter
        20. unregister_prefilter
        21. register_postfilter
        22. unregister_postfilter
        23. register_outputfilter
        24. unregister_outputfilter
        25. load_filter
        26. clear_cache
        27. clear_all_cache
        28. is_cached
        29. clear_all_assign
        30. clear_compiled_tpl
        31. template_exists
        32. get_template_vars
        33. get_config_vars
        34. trigger_error
        35. display
        36. fetch
        37. config_load
        38. get_registered_object
        39. clear_config
      3. Summary
    15. 9. Caching and Performance
      1. Caching in Smarty
      2. Dynamically Caching Template Sections
      3. Clearing the Cache
      4. Advanced Caching Features
      5. Using Cache Groups
      6. Clearing a Cache Group
      7. Avoiding the Cache
        1. Disabling a Template Cache
        2. Using {insert} to Avoid Caching
        3. Creating a Custom Plug-in to Avoid Caching on Portions of a Template
      8. Creating a Custom Cache Handler
      9. Optimizing Smarty Applications
      10. Profiling PHP
      11. Designing Sites for Effective Caching
        1. The Last-Modified and ETag Headers
        2. The Expires Header
        3. The Cache-Control Header
      12. Tools: ApacheBench (ab)
      13. Tools: Xdebug
      14. Tools: WinCacheGrind
      15. Summary
    16. 10. Extending Smarty with Plug-ins
      1. Finding and Installing Plug-ins
      2. Useful Plug-ins
        1. HTML List Plug-in
        2. File Size Format Plug-in
        3. Google Highlight Plug-in
      3. Writing your own Plug-ins
      4. Plug-in Types
        1. Functions
        2. Modifiers
        3. Block Functions
        4. Compiler Functions
        5. Prefilters, Postfilters, and Output Filters
        6. Resources
        7. Inserts
      5. Registering Plug-ins
      6. Example Plug-in: Calendar
      7. Example Plug-in: Auto-link URLs
      8. Summary
    17. 11. Filters
      1. Prefilters
      2. Postfilters
      3. Output Filters
      4. Creating Filters
      5. Registering a Filter at Run Time
      6. Manually Loading a Filter
      7. Automatically Loading a Filter
      8. Filter #1: Remove HTML Comments
      9. Filter #2: Benchmark Information
      10. Filter #3: Compress Output with gzip
      11. Filter #4: Search Engine Highlight
      12. Summary
    18. 12. Internationalization
      1. Translation Infrastructure: Gettext
      2. Configuring PHP with Gettext
      3. Simple PHP Example
      4. Setting Up the Gettext Files
      5. Using Gettext with Smarty
      6. Generating a PO File
      7. Advanced Features of Smarty Gettext
      8. Summary
    19. Index
3.145.94.251