Get Smarty

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:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Templates con Componetes

Tradicionalmente, programar templates en sus aplicaciones es de la siguiente forma: Primero, usted acumula sus variables dentro de su aplicación PHP, (talvez como requisiciones de una base de datos). Entonces, usted instancia su objeto Smarty assign(), atribuye valores a las variables y muestra el template display(). Por ejemplo nosotros tenemos un registrador de existencias en nuestro template. Nosotros recolectaremos los datos de las existencias en nuestra aplicación, entonces damos valor a estas variables en el template y lo mostramos. Ahora esto seria genial si usted adicionara este registrador de almacenamiento (stock ticker) a cualquier aplicación simplemente incluyendolo en el template, y no preocuparse hacerca de como ir a traer los datos al frente?

Usted puede escribir este plugin haciendo que traiga un contenido y asignarlo a la variable del template.

Example 18.7. Templates con Componetes

function.load_ticker.php - deja el archivo en $plugins directory


<?php

// deja el archivo "function.load_ticker.php" en el directorio de plugins

// configura nuestra funci&oacute;n para traer los datos almacenados
function fetch_ticker($symbol) 
{
   // ponga la lógica aquí que traera $ticker_name
   // y $ticker_price de algun recurso
   return $ticker_info;
}

function smarty_function_load_ticker($params, &$smarty) 
{
   // llama la función
   $ticker_info = fetch_ticker($params['symbol']);
   
   // asigna las variables al template
   $smarty->assign($params['assign'], $ticker_info);
}
?>

    

index.tpl


{load_ticker symbol="YHOO" assign="ticker"}

Stock Name: {$ticker.name} Stock Price: {$ticker.price}

    

Vea también {include_php}, {include} y {php}.

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 13 plus 4? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk