Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

include Datei als Variabel

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
smartynewcomer
Smarty n00b


Joined: 09 Oct 2013
Posts: 3

PostPosted: Wed Oct 09, 2013 9:39 am    Post subject: include Datei als Variabel Reply with quote

Hallo, ich bin absolut neu hier und habe auch fast keine Ahnung von Smarty

ich möchte in einem Template eine Funktion einbauen

wenn die Seite /demo3456.htm aufgerufen wird möchte ich in der templatexy .htm eine include Datei {include file="inc.testdemo.htm"}erscheinen lassen

und wenn die Seite //demo9675.htm dann {include file="inc.testdemo.htm"}

ich hoffe ich habe mich verständlich ausgedrückt. über jede nachricht wäre ich froh
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Wed Oct 09, 2013 9:52 am    Post subject: Reply with quote

Hey,

abgesehen davon, dass du in deinem Beispiel in beiden Fällen die selbe Datei includieren willst, kannst du in deinem PHP Code folgendes schreiben z. B.:

Code:

$q = $_SERVER['PHP_SELF'];
$p = pathinfo($q);
$fileName = $p['basename'];


Die Variable $fileName ist dann z. B. deine demo3456.htm

im Template kannst du dann mittels

Code:
{if $fileName == demo3456.htm}
{include file=xyz.tpl}
{else}
{include file=abc.tpl}
{/if}


Ist allerdings keine Schöne lösung. Man sollte im Code schon wissen, auf welcher Seite man sich befindet und was man includieren möchte und was nicht....
Back to top
View user's profile Send private message Visit poster's website
smartynewcomer
Smarty n00b


Joined: 09 Oct 2013
Posts: 3

PostPosted: Wed Oct 09, 2013 10:29 am    Post subject: danke funzt leider nicht auch bei einem verweis nicht Reply with quote

Grizzly wrote:
Hey,

abgesehen davon, dass du in deinem Beispiel in beiden Fällen die selbe Datei includieren willst, kannst du in deinem PHP Code folgendes schreiben z. B.:

Code:

$q = $_SERVER['PHP_SELF'];
$p = pathinfo($q);
$fileName = $p['basename'];


Die Variable $fileName ist dann z. B. deine demo3456.htm

im Template kannst du dann mittels

Code:
{if $fileName == demo3456.htm}
{include file=xyz.tpl}
{else}
{include file=abc.tpl}
{/if}


Ist allerdings keine Schöne lösung. Man sollte im Code schon wissen, auf welcher Seite man sich befindet und was man includieren möchte und was nicht....
Back to top
View user's profile Send private message
smartynewcomer
Smarty n00b


Joined: 09 Oct 2013
Posts: 3

PostPosted: Wed Oct 09, 2013 10:33 am    Post subject: danke Reply with quote

ich muss mich wohl hier mit dem forum noch zu recht finden .. also auch bei nur einem verweis klappt es leider nicht.

aber echt danke für deine hilfe
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Wed Oct 09, 2013 10:55 am    Post subject: Reply with quote

Was genau klappt denn nicht?

Wird die Datei nicht inkludiert oder wie?

Wenn das der Fall ist dann liegt die inkludierte Datei wahrscheinlich nicht im selben Verzeichnis wie die Datei in der Inkludiert wird. Ich hoffe das war jetzt nicht verwirrend. Also kurz:

Wenn du in der templatexyz.htm die Datei inc.testdemo.htm inkludieren willst, dann muss diese im selben Verzeichnis liegen (außer das Verzeichnis der Datei inc.testdemo.htm wurde smarty mitgeteilt)
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Oct 09, 2013 5:03 pm    Post subject: Reply with quote

Auf alle Fälle die Dateinamen in Quotes

Code:
{include file='xyz.tpl'}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP