Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Find Wedding Dresses Online at Canada from Ca-dresses.com

Find your local domestic cleaner

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Advertisement

Name

display() — displays the template

Description

void display(string template,
             string cache_id,
             string compile_id);

This displays the template unlike fetch(). Supply a valid template resource type and path. As an optional second parameter, you can pass a $cache id, see the caching section for more information.

As an optional third parameter, you can pass a $compile_id. This is in the event that you want to compile different versions of the same template, such as having separate templates compiled for different languages. Another use for $compile_id is when you use more than one $template_dir but only one $compile_dir. Set a separate $compile_id for each $template_dir, otherwise templates of the same name will overwrite each other. You can also set the $compile_id variable once instead of passing this to each call to this function.

Example 13.12. display()


<?php
include(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty();
$smarty->caching = true;

// only do db calls if cache doesn't exist
if(!$smarty->is_cached('index.tpl')) {

  // dummy up some data
  $address = '245 N 50th';
  $db_data = array(
               'City' => 'Lincoln',
               'State' => 'Nebraska',
               'Zip' => '68502'
             );

  $smarty->assign('Name', 'Fred');
  $smarty->assign('Address', $address);
  $smarty->assign('data', $db_data);

}

// display the output
$smarty->display('index.tpl');
?>

   

Example 13.13. Other display() template resource examples

Use the syntax for template resources to display files outside of the $template_dir directory.


<?php
// absolute filepath
$smarty->display('/usr/local/include/templates/header.tpl');

// absolute filepath (same thing)
$smarty->display('file:/usr/local/include/templates/header.tpl');

// windows absolute filepath (MUST use "file:" prefix)
$smarty->display('file:C:/www/pub/templates/header.tpl');

// include from template resource named "db"
$smarty->display('db:header.tpl');
?>

   

See also fetch() and template_exists().

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 20 plus 13? (Are you human?)

Advertisement

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
First Click Internet Marketing @fcinternetmarketing.com
Credit Card Processing Company