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

Auto Template Finder

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
dubhunter
Smarty Rookie


Joined: 09 Aug 2007
Posts: 13
Location: Santa Monica, CA

PostPosted: Thu Aug 09, 2007 5:20 pm    Post subject: Auto Template Finder Reply with quote

Here is another excerpt from my PageController class. This one is great for when you have a PHP stub file for every TPL...

Code:
private function genAutoTemplateName()
{
   $regex = "/^\/([^.]+)\.php$/";
   $replace = "$1.tpl";
   $this->template = preg_replace($regex, $replace, $_SERVER['PHP_SELF']);
   if (!$this->smarty->template_exists($this->template))
      $this->template = "index.tpl";
}

//USAGE:
public function showPage()
{
   if (empty($this->template))
      $this->genAutoTemplateName();
   if (!empty($this->title))
      $this->smarty->assign("title", $this->title);
   $this->smarty->assign("onload", $this->onload);
   $this->smarty->assign("page_class", $this->getPageClass());
   $this->smarty->display($this->template);
   $this->rendered = true;
}
Back to top
View user's profile Send private message Visit poster's website
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 -> Tips and Tricks 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