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

[ERLEDIGT] Alternative Templatedatei Laden...

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


Joined: 07 May 2011
Posts: 34

PostPosted: Tue Nov 12, 2013 11:15 am    Post subject: [ERLEDIGT] Alternative Templatedatei Laden... Reply with quote

Hallo Forum,

ich würde in mein Script gerne eine Möglichkeit haben um alternative Templatedateien laden zu können. Hat Smarty dafür eine Funktion?

Ich habe schon eine eigene kleine Funktion geschrieben die soweit auch funktioniert blos kann ich kein neuen Header für eine Weiterleitung setzten sofern beide Dateien nicht vorhanden sind =(

Die sollte halt vor smarty arbeiten, aber durch andere $smarty->fetch() ist header nicht mehr möglich darum würde ich jetzt gern eine Besserlösung mittels Smarty anstreben.


Code:
public static function display($file)
   {
      global $smarty;
      
      if(file_exists(BASE_URI.'app/templates/'.actives_tpl.$file.tpl_ext))
      {
         return $smarty->display($file.tpl_ext);
      }   
      else if(file_exists(BASE_URI.'app/templates/default/'.$file.tpl_ext) AND actives_tpl != 'default')
      {
         return $smarty->display('app/templates/default/'.$file.tpl_ext);
      }   
      else
      {
         header('Location: error.php?error=tpl404&file='.$file); // Template not found, redirect to errorpage
      }
   }


Also ich erstelle ein Template namens: "default" nun kann man dann später weitere Templates installieren die natürlich einen anderen namen haben werden, sollte dort eine Datei fehlen möchte ich das Smarty auf das "default" demplate zurückgreifft und versucht die Datei von hier zu laden ist die Datei auch dort nicht vorhanden soll eine Weiterleitung erfolgen

header('Location: error.php?error=tpl404&file='.$file);

Hat da Jemand Ideen oder Tipps für mich, wäre sehr dankbar für Unterstützung.


MFG: Paykoman[/code]
Back to top
View user's profile Send private message
Paykoman
Smarty Rookie


Joined: 07 May 2011
Posts: 34

PostPosted: Tue Nov 12, 2013 3:02 pm    Post subject: Reply with quote

So hat sich erledigt, da mein System mit Controllern arbeitet, konnte ich es jetzt lösen in dem das $smarty->display(); durch eine neue Funktion ersetzt ( parent::run('auth_'.self::$page); ) wurde welche im FrontController (parent) ausgeführt wird, somit kann ich dann auch hier wieder ein header() setzten für eine Weiterleitung!

Code:
public function run($file) // check templatefile if exsists
   {
      global $smarty;
      $filename = $file.tpl_ext;
      
      if( file_exists(BASE_URI.'app/templates/'.actives_tpl.$filename) )
      {
         return $smarty->display($filename);
      }
      else if( file_exists(BASE_URI.'app/templates/default/'.$filename) AND actives_tpl != 'default')
      {
         return $smarty->display('app/templates/default/'.$filename);
      }
      else
      {
         header('Location: error.php?error=tpl404&file='.$file); // Template not found, redirect to errorpage
      }
   }
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