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

Was ist sinvoller > include templates

 
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
TomTo
Smarty Rookie


Joined: 30 May 2009
Posts: 18

PostPosted: Mon Apr 02, 2012 6:15 pm    Post subject: Was ist sinvoller > include templates Reply with quote

Ich wolle mal Fragen was sinvoller ist, die Templates alle schon aus der PHP Datei einzubinden, oder aus dem erstellten Content Template zu includen ?



index.php

Code:

$smarty->display('sidebar.tpl');
 
PHP CODE
$smarty->display('content.tpl');
$smarty->display('footer.tpl');


Oder besser aus den Templates

content.tpl
Code:

{include file="sidebar.tpl"}

CONTENT

{include file="footer.tpl"}


Habe eigentlich die Erfahrung lieber gleich alles aus PHP zu machen, auch generelle If Abfragen und sontiges Vergleiche, Berechnungen sind im Template immer ungünstiger und kosten Performance.
Vielleicht sieht es aber jemand anders !?
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Tue Apr 03, 2012 12:13 pm    Post subject: Reply with quote

Das musst du selbst entscheiden. Ich persönlich mache immer pro "Seite" in display()-Aufruf. In diesem .tpl-File include ich dann den header, dann mein Zeug und schließlich auch den Footer.

Warum ich das so mache? Weil an den PHP-Code sollte keiner ran, an die .tpl-Files können von mir aus welche ran gehen und dinge ändern (kann man bei mir auch immer im ACP). Wenn du aber den Header und den Footer im PHP Code schon direkt einbaust, dann MUSS man den Code abändern. Und das will ich nicht. Denn wenn jemand (vorallem weniger erfahrene) etwas am Code macht, gebe ich kein Support mehr. Das ist (fast) überall so.

Somit musst du dich Fragen was besser ist. Wenn du also sagst "mir gefällt es besser wenn alles in der PHP-Datei ist und den Code sehe eh nur ich, da es meine Private Site ist", dann kannst dus so machen. Wenn du aber etwas publizieren willst, dann eher mit dem include-Befehl aus dem Template heraus....

Aber so rein vom Technischen, sollte eigentlich kein Unterschied sein, wie es gemacht wird!
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: Tue Apr 03, 2012 8:28 pm    Post subject: Reply with quote

Wenn Du caching benutzt gibt es schon ein Performance Unterschied. Jeder Aufruf von display() erzeugt und lädt eine eigene Cache Datei.

Für beste Performance also caching enablen und mit {include}arbeiten.
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