Smarty Template

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Smarty Template - Presentation Transcript

    1. Smarty Template Introduction Musavir Iftekhar
    2. Installation
      • Download form site.. www. smarty .net/
      • Unzip and put smarty directory under your home directory
    3. Using
      • Better to create your own folders of templates else using default.
      • <?php
      • define ( 'SMARTY_DIR', 'smarty/' );
      • require_once ( SMARTY_DIR . 'Smarty.class.php ');
      • $smarty = new Smarty();
      • $smarty->template_dir = './templates/';
      • $smarty->compile_dir = './templates/compile/';
      • $smarty->cache_dir = './templates/cache/';
      • $smarty->caching = false;
      • ?>
    4. Common syntax
      • $val = “some value”;
      • $smarty->assign(“smarty_sending_var”, $val);
      • $smarty->display(“page.tpl”);// page in template folder
      • -------------------------------------------------------
      • Page.tpl
      • {* these are comments of smarty *}
      • {$smarty_sending_var} // will show contents of sending values from the page
    5. Variable Modifiers
      • {$var|modifier}
      • {$title|capitalize} output: MYTITLE
      • {$title|count_words} output: 55
      • {$dt, “%B %e, %Y”} output: December 22, 2005
      • {$title|default:”some val”} output: if $title = null then some val
      • {$title|strip_tags} output: remove html tags from string
      • {$title|truncate:20} output: show reduce to 20 characters
    6. Control Structures
      • {if $var qualifier comprator}
      • Output
      • {elseif $var qualifier comprator}
      • Output
      • {else}
      • Output
      • {/if}
      • $my_array = array(‘val1’, ‘val2’, ‘val3’);
      • $smarty->assign(“array_val”, $my_array);
      • Handle in into template as
      • {foreach from=$my_array item=valout}
      • {$valout}
      • {/foreach}
      • If no value in array.. then
      • {foreach from=$my_array item=valout}
      • {$valout}
      • {foreachesles}
      • Output here
      • {/foreach}
    7. Section
      • $titles = arrray(‘a’, ‘b’, ‘c’);
      • $smarty->assign(“titles”, $titles);
      • $smarty->display(“titles.tpl”);
      • --------------------titles.tpl--------------------
      • {section name=book loop=$titles}
      • {$titles[book]}
      • {/section}
      • Output:abc
      • $titles = arrray(‘title’=>’Eng’, ‘author’=>’Master’, ‘pub’=>’apex’);
      • $smarty->assign(“titles”, $titles);
      • $smarty->display(“titles.tpl”);
      • --------------------titles.tpl--------------------
      • {section name=book loop=$titles}
      • {$titles[book].title}
      • {$titles[book].author}
      • {$titles[book].pub}
      • {/section}
      • Output:Eng Master apex
    8. sectionelse
      • $titles = arrray(‘a’, ‘b’, ‘c’);
      • $smarty->assign(“titles”, $titles);
      • $smarty->display(“titles.tpl”);
      • --------------------titles.tpl--------------------
      • {section name=book loop=$titles}
      • {$titles[book]}
      • {sectionelse}
      • Output: if array = null
      • {/section}
      • Output:abc
    9. Include
      • {include file=“/usr/local/lib/pmnp/header.tpl”}
      • {* Execute some other Smarty statements here. *}
      • {include file=“/usr/local/temps/footer.tpl”}
      • {include file=“/local/header.tpl” title=“My home page”}
    10. Insert
      • Insert some advertisement page
      • function insert_banner(){
      • }
      • ------------------tpl file-----------------------------
      • <img src=“imgs/{insert name=“banner”}.gif”/>
    11. CSS with literal tag
      • Insert css into tpl file directly
      • <html><head>
      • {literal}<style type=“text/css”>
      • P{Margin: 5px;}
      • </style>
      • {/literal}
      • </head>
      • User Link to connect with outer css file
      • <link style=“text/css” href=“mycss.css” />
    12. Caches
      • $smarty->caching = 1

    + mussawir20mussawir20, 2 years ago

    custom

    330 views, 0 favs, 0 embeds more stats

    Summary of smarty usage and functions

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 330
      • 330 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 12
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories