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

include_php (PHP-Code einbinden)

Die Verwendung von {include_php} wird nicht mehr empfohlen, die gleiche funktionalität kann auch mit Template/Script Komponenten erreicht werden.

Attribut Name Typ Erforderlich Standardwert Beschreibung
file string Ja n/a Der Name der einzubindenden PHP-Datei.
once boolean Nein true Definiert ob die Datei mehrmals geladen werden soll, falls sie mehrmals eingebunden wird.
assign string Nein n/a Der Name der Variable, der die Ausgabe von include_php zugewiesen wird.

Falls Sicherheit aktiviert ist, muss das einzubindende Skript im $trusted_dir Pfad liegen. {include_php} muss das Attribut 'file' übergeben werden, das den Pfad - entweder relativ zu $trusted_dir oder absolut - zum Skript enthält.

Normalerweise wird ein PHP-Skript nur einmal pro Aufruf geladen, selbst wenn es mehrfach eingebunden wird. Sie können dieses Verhalten durch die Verwendung des once Attributs steuern. Wenn Sie 'once' auf 'false' setzen, wird die Datei immer wenn sie eingebunden wird auch neu geladen.

Optional kann das assign Attribut übergeben werden. Die Ausgabe von include_php wird dann nicht direkt eingefügt, sondern in der durch assign benannten Template-Variable abgelegt.

Das Objekt '$smarty' kann in dem eingebundenen PHP-Script über '$this' angesprochen werden.

Example 7.12. Funktion include_php

lade_nav.php


<?php
 
 // lade die Variablen aus einer MySQL-Datenbank und weise sie dem Template zu
 require_once("MySQL.class.php");
 $sql = new MySQL;
 $sql->query("select * from site_nav_sections order by name",SQL_ALL);
 $this->assign($sections,$sql->record);

?>

  

Bei folgendem index.tpl:


{* absoluter Pfad, oder relativ zu '$trusted_dir' *}
{include_php file="/pfad/zu/lade_nav.php"}

{foreach item=$aktuelle_section from=$sections}
 <a href="{$aktuelle_section.url}">{$aktuelle_section.name}</a><br>
{/foreach}

  

Siehe auch {include}, {php}, {capture}, Template Ressourcen and Template/Script Komponenten

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 5 plus 13? (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