What is Smarty?
Why use it?
Use Cases and Work Flow
Syntax Comparison
Template Inheritance
Best Practices
Crash Course
You may use the Smarty logo according to the trademark notice.
For sponsorship, advertising, news or other inquiries, contact us at:
display() — Despliega el Template
void display(string template,
string cache_id,
string compile_id);
Este despliega el template diferente de fetch(). Cargando un tipo valido de path template resource. Como un segundo parámetro opcional, usted puede pasar un identificador de cache. Vea el caching section para mayor información.
Como tercer parametro opcional, usted puede pasar compile_id
.
Este en el caso que usted quira compilar diferentes versiones del mismo Tempalte,
tal como tener separadas varios Templates compilados de diferentes lenguajes.
Otro uso para compile_id es cuando usted usa mas de un $template_dir pero solo un $compile_dir.
Ponga separado compile_id
por cada $template_dir, de otra manera
los tempate con el mismo nombre se sobre escibiran uno sobre otro.
Uste puede poner también la variable $compile_id
una vez en lugar de pasar esta por cada llamada a la función.
Example 13.12. display()
<?php include("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($db_data); } // display the output $smarty->display("index.tpl"); ?>
Use la sintaxis template resources para mostrar archivos fuera del directorio $template_dir.
Example 13.13. Ejemplos de recursos de la función display
<?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'); ?>
Ver también fetch() y template_exists().