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

Array for $template_dir
Goto page Previous  1, 2
 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Apr 17, 2003 10:55 pm    Post subject: Reply with quote

I agree with you messju, I'd keep things the way they are. BUT, it sounds like sometimes people don't want file: to be the default resource. ie. they don't like 'path:whatever.tpl'. I see that as the whole point of people asking file: to support arrays--they CAN do it with a resource, but then they would have to use explicit resource naming when calling their templates.

I actually think explicit resources are better, but hey, that's me. Why, I even prefer 'file:mytemplate.tpl' to 'mytemplate.tpl'.

Thanks for posting the code, that will give people something to actually use. Wink

xo boots
Back to top
View user's profile Send private message
Tom Sommer
Administrator


Joined: 16 Apr 2003
Posts: 47
Location: Denmark

PostPosted: Thu Apr 17, 2003 10:56 pm    Post subject: Reply with quote

Evil code, messju Very Happy

Anyway, how does this gettext stuff work? (off topic Smile)
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Apr 21, 2003 4:18 pm    Post subject: Reply with quote

uh, there is one thing i totally forgot: $smarty->default_template_handler_func
(okay the docs on http://smarty.php.net/manual/en/variable.default.template.handler.func.php
are a bit sparse, but a grep in the source shows immediately how it works:) )

it is called when a template cannot be found. this can also be used as a hook for a search-path-function.

man, i was pretty sure i knew all of smarty's features, but now i know better... Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
alan
Smarty Regular


Joined: 17 Apr 2003
Posts: 43

PostPosted: Mon Apr 21, 2003 6:42 pm    Post subject: Reply with quote

Well, I've been expermenting with that, however I'm still having problems...

The idea was to have a full theme system, which if the theme provides a template for a particular task, then the system will use that, otherwise it will use the default template.

Code:
class SmartyTheme extends Smarty
{
   var $theme_dir     = "themes";
   var $default_theme = "default";
   var $current_theme = "default";
   var $_handler      = "";

   function SmartyTheme( )
   {
      // save the old handler (in case someone has modified smarty itself

      $this->_handler  = $this->default_template_handler_func;

      // set the new handler

      $this->default_template_handler_func = "_smartytheme_template_handler_function";

      // initialize the original class

      $this->Smarty();
   }

   function get_theme( )
   {
      return $this->current_theme;
   }

   function set_theme( $theme = null )
   {
      $result = $this->current_theme;

      if (!is_null($theme))
      {
         $this->current_theme = $theme;
      }

      return $result;
   }
}

function _smartytheme_template_handler_function( $resourceType, $resourceName, &$templateSource, &$templateTimestamp, &$smartyObject )
{
   // check in the current theme folder

   if ($resourceType == "file")
   {
      $temp     = $smartyObject->compile_dir;
      $filename = $smartyObject->theme_dir . "/" . $smartyObject->current_theme . "/" . $smartyObject->template_dir . "/" . $resourceName;

      $smartyObject->compile_dir = $smartObject->compile_dir . "/" . $themes . "/" . $smartyObject->current_theme;

      if (is_readable($filename))
      {
         $templateSource    = $smartyObject->_read_file($filename);
         $templateTimestamp = filemtime($filename);

         return true;
      }

      if ($smartyObject->current_theme != $smartyObject->default_theme)
      {
         $filename = $smartyObject->theme_dir . "/" . $smartyObject->default_theme . "/" . $smartyObject->template_dir . "/" . $resourceName;

         if (is_readable($filename))
         {
            $templateSource    = $smartyObject->_read_file($filename);
            $templateTimestamp = filemtime($filename);

            return true;
         }
      }

      $smartyObject->compile_dir = $temp;
   }

   // call the old handler (if it exists

   if (($handler = $smartyObject->_handler) != "")
   {
      return $handler($resourceType, $resourceName, $templateSource, $templateTimestamp, $smartyObject);
   }

   // oops, nothing found

   return false;
}


This is just a start, and whilst it ~appears~ to work on my system, I'm not sure if it's anywhere near production quality.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Apr 21, 2003 8:01 pm    Post subject: Reply with quote

messju, I was looking at that function myself but decided to investigate because it seemed to me that it would always incur a useless filesystem call before it is invoked.
Back to top
View user's profile Send private message
Roc
Smarty Rookie


Joined: 17 Apr 2003
Posts: 15

PostPosted: Mon Apr 21, 2003 9:35 pm    Post subject: Reply with quote

I also like the idea of a $default_resource_type (see poll thread). This will also make the lookup of template files transparent. What I like to avoid is a need for "path:" e.g.

Code:

{include file="path:xyz.tpl"}


cause templates for my projects are often made by designers who will not always understand while the resource type is necessary and likely forget to add it.
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 -> Feature Requests All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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