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

{php}

Les balises {php} permettent de rajouter du code PHP directement dans le template. Ils ne seront pas ignorés, quelle que soit la valeur de $php_handling. Pour les utilisateurs avancés seulement, son utilisation n'est normalement pas nécessaire et n'est pas recommandée.

Notes techniques

Pour accéder aux variables PHP dans les blocks {php}, vous devriez avoir besoin d'utiliser le mot clé PHP global.

Example 7.28. Exemple avec la balise {php}


{php}
   // inclusion directe d'un script PHP depuis le template.
   include('/chemin/vers/display_weather.php');
{/php}

  

Example 7.29. Balises {php} avec le mot clé global et assignement d'une variable


{* ce template inclut un bloc {php} qui assigne la variable $varX *}
{php}
   global $foo, $bar;
   if($foo == $bar){
     echo 'Ceci apparaîtera dans le template';
   }
$this->assign('varX','Strawberry');
{/php}
{* affichage de la variable *}
<strong>{$varX}</strong> est ma glâce favorite :-)

  

Voir aussi $php_handling, {include_php}, {include}, {insert} et les templates composantes.

Comments
by anonymous on May 24, 2012 at 6:48
Bonjour, Dans le fichier "product-list.tpl", dans la boucle "{foreach from=$products item=product name=products}", je voudrais récupéré dans mes balises "{php} {/php}" la variable "$product->id" que j'utiliserai dans une fonction php que j'ai créée. Avez-vous une solution? Merci
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 2 plus 18? (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