SlideShare a Scribd company logo
Smarty 3 overview

http://www.smarty.net/v3_overview



how to overcome the present difficulties while upgrading to smarty3

reference url

1. {$array|mod} and {$array|@mod} behave identical

2. Smarty 3 is PHP 5 only. It will not work with PHP 4

3. The use of {php} tags is deprecated. It can be enabled with $smarty-
>allow_php_tag=true.

4. == Delimiters and whitespace ==
Delimiters surrounded by whitespace are no longer treated as Smarty tags.
Therefore, { foo } will not compile as a tag, you must use {foo}. This change
Makes Javascript/CSS easier to work with, eliminating the need for {literal}.
This can be disabled by setting $smarty->auto_literal = false;

5. == Unquoted Strings ==
Smarty 2 was a bit more forgiving (and ambiguous) when it comes to unquoted
strings
in parameters. Smarty3 is more restrictive. You can still pass strings
without quotes
so long as they contain no special characters. (anything outside of A-Za-z0-
9_)

For example filename strings must be quoted
<source lang="smarty">
{include file='path/foo.tpl'}
</source>

6.== Extending the Smarty class ==
If you are extending
the Smarty class, its constructor is not called implicitly if the your child
class defines
its own constructor. In order to run Smarty's constructor, a call to
parent::__construct()
within your child constructor is required.

<source lang="php">
class MySmarty extends Smarty {
   function __construct() {
       parent::__construct();

         // your initialization code goes here

   }
}
</source>
7.== Scope of Special Smarty Variables ==

In Smarty 2 the special Smarty variables $smarty.section... and
$smarty.foreach...
had global scope. If you had loops with the same name in subtemplates you
could accidentally
overwrite values of parent template.

In Smarty 3 these special Smarty variable have only local scope in the
template which
is defining the loop. If you need their value in a subtemplate you have to
pass them
as parameter.
<source lang="smarty">
{include file='path/foo.tpl' index=$smarty.section.foo.index}
</source>


8. == SMARTY_RESOURCE_CHAR_SET ==
Smarty 3 sets the constant SMARTY_RESOURCE_CHAR_SET to utf-8 as default
template charset.
This is now used also on modifiers like escape as default charset. If your
templates use
other charsets make sure that you define the constant accordingly. Otherwise
you may not
get any output.


9. == trigger_error() ==
The API function trigger_error() has been removed because it did just map to
PHP trigger_error.
However it's still included in the Smarty2 API wrapper


10. == Smarty constants ==
The constants
SMARTY_PHP_PASSTHRU
SMARTY_PHP_QUOTE
SMARTY_PHP_REMOVE
SMARTY_PHP_ALLOW
have been replaced with class constants
Smarty::PHP_PASSTHRU
Smarty::PHP_QUOTE
Smarty::PHP_REMOVE
Smarty::PHP_ALLOW




Need to understand more

11. == newline at {if} tags ==
A n was added to the compiled code of the {if},{else},{elseif},{/if} tags to
get output of newlines as expected by the template source.
If one of the {if} tags is at the line end you will now get a newline in the
HTML output.

12. == Autoloader ==
Smarty 3 does register its own autoloader with spl_autoload_register. If your
code has
an existing __autoload function then this function must be explicitly
registered on
the __autoload stack. See http://us3.php.net/manual/en/function.spl-autoload-
register.php
for further details.

13.== Plugin Filenames ==
Smarty 3 optionally supports the PHP spl_autoloader. The autoloader requires
filenames
to be lower case. Because of this, Smarty plugin file names must also be
lowercase.
In Smarty 2, mixed case file names did work.



new feature examples
http://www.smarty.net/v3_overview

1. Rewritten for PHP 5

2. New Lexer/Parser:

Smarty has a new template parser, a real syntax lexer. This gives Smarty much finer control over its
template syntax. Things like in-template math, line-precision error messages and recursive template
functions are now possible.

3. Template Objects

http://www.smarty.net/docs/en/api.create.template.tpl

You can now make template objects and execute them independently. Example:

$tpl = $smarty->createTemplate('my.tpl');
$tpl->assign('foo','bar');
$smarty->display($tpl); // or $tpl->display();



Data Objects:-

The variables assigned to a template can now be managed independently as a Smarty_Data object.
Example:
$data = new Smarty_Data;

$data->assign('foo','bar');

$smarty->display('my.tpl',$data);

$tpl = $smarty->createTemplate('my.tpl',$data);



Template Inheritance

Templates can now inherit from each other. You mark blocks of a template with {block
name=foo}{/block} tags, a template can inherit with the {extend file="my.tpl"} tag, and then you can
replace, change or append the blocked contents from the inheriting template(s).

Example:

parent .tpl
<html>
  <head>
         <title>{block name=title}default title{/block}<title>
  </head>
  <body>
         {block name=body}default body{/block}
  </body>
</html>


child .tpl
{extends file="parent.tpl"}
{block name=title}My Child Title{/block}
{block name=body}My Child Body{/block}


output of $smarty->display('child.tpl');
<html>
  <head>
         <title>My Child Title<title>
  </head>
  <body>
         My Child Body
  </body>
</html>
In-Template Function Definitions:-

Smarty
{* define the function *}
{function name=menu level=0}
  <ul class="level{$level}">
  {foreach $data as $entry}
    {if is_array($entry)}
      <li>{$entry@key}</li>
      {menu data=$entry level=$level+1}
    {else}
      <li>{$entry}</li>
    {/if}
  {/foreach}
  </ul>
{/function}

{* create an array to demonstrate *}
{$menu = ['item1','item2','item3' => ['item3-1','item3-2','item3-3' =>
['item3-3-1','item3-3-2']],'item4']}

{* run the array through the function *}
{menu data=$menu}


Output
* item1
* item2
* item3
      o item3-1
      o item3-2
      o item3-3
            + item3-3-1
            + item3-3-2
* item4

More Related Content

What's hot

Subroutines in perl
Subroutines in perlSubroutines in perl
Subroutines in perl
sana mateen
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
sana mateen
 
Dsl
DslDsl
Dsl
phoet
 
Python Function
Python FunctionPython Function
Python Function
Soba Arjun
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Henry Osborne
 
Fast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packagesFast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packages
Feras Ahmad
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)
RORLAB
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
IIUM
 
lab4_php
lab4_phplab4_php
lab4_php
tutorialsruby
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
eSparkBiz
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
sana mateen
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
Nicole Ryan
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
Joe Jiang
 
Smarty Template Engine
Smarty Template EngineSmarty Template Engine
Smarty Template Engine
Mustafa Kırımlı
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applications
amichoksi
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
Vineet Kumar Saini
 
PHP
PHP PHP
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
mysql ....question and answer by muhammed thanveer melayi
mysql ....question and answer by muhammed thanveer melayimysql ....question and answer by muhammed thanveer melayi
mysql ....question and answer by muhammed thanveer melayi
Muhammed Thanveer M
 

What's hot (20)

Subroutines in perl
Subroutines in perlSubroutines in perl
Subroutines in perl
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Dsl
DslDsl
Dsl
 
Python Function
Python FunctionPython Function
Python Function
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Fast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packagesFast formula queries for functions, contexts, db is and packages
Fast formula queries for functions, contexts, db is and packages
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
lab4_php
lab4_phplab4_php
lab4_php
 
In-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTMLIn-Depth Guide On WordPress Coding Standards For PHP & HTML
In-Depth Guide On WordPress Coding Standards For PHP & HTML
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Smarty Template Engine
Smarty Template EngineSmarty Template Engine
Smarty Template Engine
 
Internet Technology and its Applications
Internet Technology and its ApplicationsInternet Technology and its Applications
Internet Technology and its Applications
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
PHP
PHP PHP
PHP
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
mysql ....question and answer by muhammed thanveer melayi
mysql ....question and answer by muhammed thanveer melayimysql ....question and answer by muhammed thanveer melayi
mysql ....question and answer by muhammed thanveer melayi
 

Similar to Smarty 3 overview

Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 
Smarty
SmartySmarty
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
drubb
 
Apache Hacks
Apache HacksApache Hacks
Apache Hacks
Beth Skwarecki
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
Ted Kulp
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Template
guest48224
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Template
mussawir20
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
tutorialsruby
 
Little Gems in TYPO3 v12
Little Gems in TYPO3 v12Little Gems in TYPO3 v12
Little Gems in TYPO3 v12
Jigal van Hemert
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
Agiliq Info Solutions India Pvt Ltd
 
How to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis moduleHow to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis module
Priyobroto Ghosh (Mule ESB Certified)
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig
Michael Peacock
 
7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!
Bartłomiej Krztuk
 
HTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
Dean Hamstead
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Rails 3 hints
Rails 3 hintsRails 3 hints
Rails 3 hints
Tiago Cardoso
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
Alexei Gorobets
 

Similar to Smarty 3 overview (20)

Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Smarty
SmartySmarty
Smarty
 
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
 
Apache Hacks
Apache HacksApache Hacks
Apache Hacks
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Template
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Template
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Little Gems in TYPO3 v12
Little Gems in TYPO3 v12Little Gems in TYPO3 v12
Little Gems in TYPO3 v12
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 
How to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis moduleHow to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis module
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig
 
7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!
 
HTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Rails 3 hints
Rails 3 hintsRails 3 hints
Rails 3 hints
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 

Recently uploaded

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 

Recently uploaded (20)

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 

Smarty 3 overview

  • 1. Smarty 3 overview http://www.smarty.net/v3_overview how to overcome the present difficulties while upgrading to smarty3 reference url 1. {$array|mod} and {$array|@mod} behave identical 2. Smarty 3 is PHP 5 only. It will not work with PHP 4 3. The use of {php} tags is deprecated. It can be enabled with $smarty- >allow_php_tag=true. 4. == Delimiters and whitespace == Delimiters surrounded by whitespace are no longer treated as Smarty tags. Therefore, { foo } will not compile as a tag, you must use {foo}. This change Makes Javascript/CSS easier to work with, eliminating the need for {literal}. This can be disabled by setting $smarty->auto_literal = false; 5. == Unquoted Strings == Smarty 2 was a bit more forgiving (and ambiguous) when it comes to unquoted strings in parameters. Smarty3 is more restrictive. You can still pass strings without quotes so long as they contain no special characters. (anything outside of A-Za-z0- 9_) For example filename strings must be quoted <source lang="smarty"> {include file='path/foo.tpl'} </source> 6.== Extending the Smarty class == If you are extending the Smarty class, its constructor is not called implicitly if the your child class defines its own constructor. In order to run Smarty's constructor, a call to parent::__construct() within your child constructor is required. <source lang="php"> class MySmarty extends Smarty { function __construct() { parent::__construct(); // your initialization code goes here } } </source>
  • 2. 7.== Scope of Special Smarty Variables == In Smarty 2 the special Smarty variables $smarty.section... and $smarty.foreach... had global scope. If you had loops with the same name in subtemplates you could accidentally overwrite values of parent template. In Smarty 3 these special Smarty variable have only local scope in the template which is defining the loop. If you need their value in a subtemplate you have to pass them as parameter. <source lang="smarty"> {include file='path/foo.tpl' index=$smarty.section.foo.index} </source> 8. == SMARTY_RESOURCE_CHAR_SET == Smarty 3 sets the constant SMARTY_RESOURCE_CHAR_SET to utf-8 as default template charset. This is now used also on modifiers like escape as default charset. If your templates use other charsets make sure that you define the constant accordingly. Otherwise you may not get any output. 9. == trigger_error() == The API function trigger_error() has been removed because it did just map to PHP trigger_error. However it's still included in the Smarty2 API wrapper 10. == Smarty constants == The constants SMARTY_PHP_PASSTHRU SMARTY_PHP_QUOTE SMARTY_PHP_REMOVE SMARTY_PHP_ALLOW have been replaced with class constants Smarty::PHP_PASSTHRU Smarty::PHP_QUOTE Smarty::PHP_REMOVE Smarty::PHP_ALLOW Need to understand more 11. == newline at {if} tags == A n was added to the compiled code of the {if},{else},{elseif},{/if} tags to get output of newlines as expected by the template source.
  • 3. If one of the {if} tags is at the line end you will now get a newline in the HTML output. 12. == Autoloader == Smarty 3 does register its own autoloader with spl_autoload_register. If your code has an existing __autoload function then this function must be explicitly registered on the __autoload stack. See http://us3.php.net/manual/en/function.spl-autoload- register.php for further details. 13.== Plugin Filenames == Smarty 3 optionally supports the PHP spl_autoloader. The autoloader requires filenames to be lower case. Because of this, Smarty plugin file names must also be lowercase. In Smarty 2, mixed case file names did work. new feature examples http://www.smarty.net/v3_overview 1. Rewritten for PHP 5 2. New Lexer/Parser: Smarty has a new template parser, a real syntax lexer. This gives Smarty much finer control over its template syntax. Things like in-template math, line-precision error messages and recursive template functions are now possible. 3. Template Objects http://www.smarty.net/docs/en/api.create.template.tpl You can now make template objects and execute them independently. Example: $tpl = $smarty->createTemplate('my.tpl'); $tpl->assign('foo','bar'); $smarty->display($tpl); // or $tpl->display(); Data Objects:- The variables assigned to a template can now be managed independently as a Smarty_Data object. Example:
  • 4. $data = new Smarty_Data; $data->assign('foo','bar'); $smarty->display('my.tpl',$data); $tpl = $smarty->createTemplate('my.tpl',$data); Template Inheritance Templates can now inherit from each other. You mark blocks of a template with {block name=foo}{/block} tags, a template can inherit with the {extend file="my.tpl"} tag, and then you can replace, change or append the blocked contents from the inheriting template(s). Example: parent .tpl <html> <head> <title>{block name=title}default title{/block}<title> </head> <body> {block name=body}default body{/block} </body> </html> child .tpl {extends file="parent.tpl"} {block name=title}My Child Title{/block} {block name=body}My Child Body{/block} output of $smarty->display('child.tpl'); <html> <head> <title>My Child Title<title> </head> <body> My Child Body </body> </html>
  • 5. In-Template Function Definitions:- Smarty {* define the function *} {function name=menu level=0} <ul class="level{$level}"> {foreach $data as $entry} {if is_array($entry)} <li>{$entry@key}</li> {menu data=$entry level=$level+1} {else} <li>{$entry}</li> {/if} {/foreach} </ul> {/function} {* create an array to demonstrate *} {$menu = ['item1','item2','item3' => ['item3-1','item3-2','item3-3' => ['item3-3-1','item3-3-2']],'item4']} {* run the array through the function *} {menu data=$menu} Output * item1 * item2 * item3 o item3-1 o item3-2 o item3-3 + item3-3-1 + item3-3-2 * item4