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

file include mit php varibale

 
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
hackmac500
Smarty n00b


Joined: 19 Sep 2013
Posts: 3

PostPosted: Thu Sep 19, 2013 3:02 am    Post subject: file include mit php varibale Reply with quote

Ich möchte php dateien dynamisch in ein smarty.tpl einbinden.

das sieh wie folgt aus:

Ich hab mehrere kategorien
a
b
c
d
e


auf die kategorien wird mittels einer template variablen namens {$category} zugegriffen. der code steht in einer datei namens global-category.tpl

nun möchte ich zu den jeweiligen katgorien verschiden php dateien einbinden.

http://domain.xy/index.php?c=1
http://domain.xy/index.php?c=14
http://domain.xy/index.php?c=8
http://domain.xy/index.php?c=6
http://domain.xy/index.php?c=3

d.h. also

Wenn ich Kategorie a aufrufe {include file="http://domain.xy/index.php?c=1"}
Wenn ich Kategorie b aufrufe {include file="http://domain.xy/index.php?c=14"}
Wenn ich Kategorie c aufrufe {include file="http://domain.xy/index.php?c=8"}
Wenn ich Kategorie d aufrufe {include file="http://domain.xy/index.php?c=6"}
Wenn ich Kategorie e aufrufe {include file="http://domain.xy/index.php?c=3"}


Wenn ich eine zeile so {include file="http://domain.xy/index.php?c=1"} in in die global-category.tpl schreibe und die seite aufrufe wird die php page korrekt eingebunden.

!!!!Nur ist das ganze dann natürlich nicht dynamisch. !!!!

Ich weiss das es möglich ist dnymische .tpl einzubinden
{include file='$dynamic.tpl'}

Mit include php habe ich bis jetzt keine passende lösung gefunden.


Ich habe bis jetz folgende Versuche unternommen

##############################################
1.

Ich habe der variablen $category ein weiters feld $category.linkid hinzugefügt in der ich die zahl am ende der url speicher.
Besipiel:

Wenn ich Kategorie a aufrufe {include file="http://domain.xy/index.php?c=1"}
Wenn ich Kategorie b aufrufe {include file="http://domain.xy/index.php?c=14"}

Kategorie a hat die category.linkid 1
Kategorie b hat die category.linkid 14

Wenn ich die varibale {$category.linkid} in die global-category.tpl schreibe und die seite aufrufe dann wird die zahl der variablen korrekt ausgegeben.
Aber der nachfolgende code kann die externe seite nicht laden. Das andere script gibt aus das die seite nicht gefunden werden kann.

d.h. die variable $category.link konnte nicht verabeitet werden.

Auch mit "Backticks" ´´ keinen Erfolg

############### CODE ###########################


Code:
{template file="global-header.tpl"}
--CODE--

{include file="http://domain.xy/index.php?c=$category.linkid"}

{include file="http://domain.xy/index.php?c=´$category.linkid´"}

{template file="global-footer.tpl"}

########################################################################################
########################################################################################

2.

Ich habe versucht das Ganze in einer neuen Variablen zu speichern und dann über eine if-Anweisung aufzurufen.
Wenn ich die Seite aufrufe wird die php page nicht eingebunden der Rest von meinem code wird korrekt dargestellt.

################## CODE #################################

Code:
{template file="global-header.tpl"}
--CODE--

{assign var=$linkid value=`$category.linkid`}
{if $linkid=="2"}
{include file="http://domain.xy/index.php?c=1"}
{elseif $linkid=="14"}
{include file="http://domain.xy/index.php?c=14"}
{/if}

usw.

{template file="global-footer.tpl"}

##########################################################################################
##########################################################################################
3.

Dann habe ich versucht jede url direkt in einer Varibalen {$category.link} zu speichern.

Bespiel:

Kategorie a hat den $category.link -> http://domain.xy/index.php?c=1

Keine der beiden Zeilen im Code unten funktioniert. wenn ich die Variable so {$category.link} in die global-category.tpl schreib und aufrufe wird die url korrekt als text ausgegeben.

########################### CODE ########################################################
Code:
{template file="global-header.tpl"}
--CODE--

{include file="$category.idlx"}

{include file="´$category.idlx´"}


{template file="global-footer.tpl"}



#######################################################################################


Wäre sehr dankbar für Hilfe und ein paar Anstöße
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Sep 19, 2013 5:01 am    Post subject: Reply with quote

Mit {include} kannst Du einen Smarty Template einbinden.

Um eine WEB page von einer URL zu lagen gibt es das {fetch} plugin.

{fetch file="http://domain.xy/index.php?c=$category.linkid"}
Back to top
View user's profile Send private message
hackmac500
Smarty n00b


Joined: 19 Sep 2013
Posts: 3

PostPosted: Thu Sep 19, 2013 2:13 pm    Post subject: Reply with quote

Quote:
Mit {include} kannst Du einen Smarty Template einbinden.

Um eine WEB page von einer URL zu lagen gibt es das {fetch} plugin.

{fetch file="http://domain.xy/index.php?c=$category.linkid"}


danke für die schnelle antwort.

wenn ich die zeile so einbinde wird sie als text auf der seite ausgegeben.

muss ich das plugin vorher aktivieren?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Sep 19, 2013 4:23 pm    Post subject: Reply with quote

Das verstehe ich jetzt gar nicht, {fetch} ist ein standard Smarty pugin aus dem plugins Verzeichnis,

Siehe http://www.smarty.net/docs/en/language.function.fetch.tpl
Back to top
View user's profile Send private message
hackmac500
Smarty n00b


Joined: 19 Sep 2013
Posts: 3

PostPosted: Fri Sep 20, 2013 2:55 pm    Post subject: Reply with quote

ich nutze ein cms indem man die fetch funktion function nicht nutzen kann. hab den admin angeschrieben und der sgat das die für das script nicht zur verfügung steht. was auch immer das heisssen mag.

es müsste doch möglich sein ein plugin nachträglich einzubinden. ich weiss nur nicht nach welchen variblen ich da suchen muss. hab im netz diesen source code gefunden.

http://peej.github.io/phpdoctor/examples/smarty/source/plugins/function.fetch.php.html.

danke für die lösungsansätze!

ich habe es jetzt so gelöst. zwar nicht so elegant aber es läuft.
Code:


{if $category.name == 'a'}
{php}
$url = file_get_contents('http://domain.xy/index.php?c=1');
echo xurl;
{/php}
{elseif $category.name == 'b'}
{php}
$url = file_get_contents('http://domain.xy/index.php?c=5');
echo $url;
{/php}

usw.
.
.
.
{/if}
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Sep 20, 2013 3:01 pm    Post subject: Reply with quote

Einfach function.fetch.php in das plugins Verzeichnis von Smarty kopieren.
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