Smarty Template

  • Uploaded by: mussawir
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Smarty Template as PDF for free.

More details

  • Words: 295
  • Pages: 14
Smarty Template Introduction

Musavir Iftekhar

Installation • Download form site.. www.smarty.net/ • Unzip and put smarty directory under your home directory

Using •

Better to create your own folders of templates else using default.


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; ?>

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

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

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}

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

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

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”}

Insert • Insert some advertisement page function insert_banner(){ } ------------------tpl file----------------------------

CSS with literal tag Insert css into tpl file directly {literal}<style type=“text/css”> P{Margin: 5px;} {/literal} User Link to connect with outer css file

Caches $smarty->caching = 1

Related Documents

Smarty Template
November 2019 9
Smarty 2.6.11
October 2019 20
Smarty Manual
November 2019 9
Smarty 2.6.14 Documents
October 2019 7
Smarty 2.6.5 Docs
June 2020 12
Smarty 2.6.14 Docs
April 2020 8

More Documents from ""

Smarty Template
November 2019 9