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

Funções Compiladoras

Funções compiladoras só são chamadas durante a compilação do template. Elas são úteis para injeção de código PHP ou conteúdo estático time-sensitive dentro do template. Se há ambos, uma função compiladora e uma função customizável registrada sob o mesmo nome, a função compiladora tem precedência.

mixed smarty_compiler_name( $tag_arg,  
  &$smarty);  
string $tag_arg;
object &$smarty;
 

À função compiladora são passados dois parâmetros: a tag string de argumento da tag - basicamente, tudo a partir do nome da função até o delimitador de fechamento, e o objeto da Smarty. É suposto que retorna o código PHP para ser injetado dentro do template compilado.

See also register_compiler_function(), unregister_compiler_function().

Example 16.6. função compiladora simples

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     compiler.tplheader.php
 * Type:     compiler
 * Name:     tplheader
 * Purpose:  Output header containing the source file name and
 *           the time it was compiled.
 * -------------------------------------------------------------
 */
function smarty_compiler_tplheader($tag_arg, &$smarty)
{
    return "\necho '" . $smarty->_current_file . " compiled at " . date('Y-m-d H:M'). "';";
}
?>

Esta função pode ser chamada em um template da seguinte forma:

{* esta função é executada somente no tempo de compilação *}
{tplheader}

O código PHP resultante no template compilado seria algo assim:

<php
echo 'index.tpl compiled at 2002-02-20 20:02';
?>

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 3 plus 9? (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