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

Evitare il parsing di Smarty

A volte è desiderabile o necessario che Smarty ignori sezioni che altrimenti verrebbero analizzate. Un esempio tipico è l'incorporazione di codice Javascript o CSS in un template. Il problema nasce dal fatto che questi linguaggi utilizzano i caratteri { e } che per Smarty sono i delimitatori di default.

La cosa più semplice sarebbe evitare queste situazioni tenendo il codice Javascript e CSS separato in appositi file e usando i collegamenti standard dell'HTML per recuperarli.

E' possibile includere contenuto letterale usando blocchi di questo tipo: {literal} .. {/literal}. Potete anche usare, in modo simile alle entità HTML, {ldelim},{rdelim} oppure {$smarty.ldelim},{$smarty.rdelim} per visualizzare i delimitatori senza che Smarty ne analizzi il contenuto.

Spesso risulta semplicemente conveniente cambiare il $left_delimiter ed il $right_delimiter di Smarty.

Example 3.6. esempio di cambio dei delimitatori


<?php

$smarty = new Smarty;
$smarty->left_delimiter = '<!--{';
$smarty->right_delimiter = '}-->';
$smarty->assign('foo', 'bar');
$smarty->display('example.tpl');

?>

  

Dove example.tpl è:


<script language="javascript">
var foo = <!--{$foo}-->;
function dosomething() {
    alert("foo is " + foo);
}
dosomething();
</script>

  

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 6 plus 15? (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