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

Default Extension?

 
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 -> General
View previous topic :: View next topic  
Author Message
sileence
Smarty n00b


Joined: 14 Nov 2010
Posts: 4

PostPosted: Wed Dec 01, 2010 4:35 pm    Post subject: Default Extension? Reply with quote

{intro}
Hi! I'm very new here, even I have used Smarty before

I have a framework writed by my own which uses a template system writed by my own too. I'm looking to Smarty3 and it seems very cool and I decided to discontinuated my template engine and start using Smarty3.

But I'm used to do a couple of things and I'd like to know if I can do the same using smarty.
{/intro}


Is there a way of setting a default extension to all the templates? I always used ".tpl" in all my templates and I don't like to specify it over and over when using display, extends, include, etc. etc. I'd like to know if there is a better way than doing it manually or parching smarty

Regards
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Dec 01, 2010 4:38 pm    Post subject: Reply with quote

#1) you can use any extension you like for smarty template files

#2) you must use the full name of the template file when calling extends/display/fetch/etc. If you want to skip the extension, write a custom resource handler that tacks on the extension for you.

http://www.smarty.net/docs/en/template.resources.tpl
Back to top
View user's profile Send private message Visit poster's website
sileence
Smarty n00b


Joined: 14 Nov 2010
Posts: 4

PostPosted: Wed Dec 01, 2010 4:48 pm    Post subject: Reply with quote

Wow, very fast answer. Thank you.

I already replaced the display method, but it doesn't help too much, I think it just creates overhead and inconsistency because I need to specify the .tpl extensions in the other methods anyway, right?

Code:
public function display($template, $cache_id = null, $compile_id = null, $parent = null)
{
  parent::display($template . '.tpl', $cache_id, $compile_id, $parent);
}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Dec 01, 2010 5:11 pm    Post subject: Reply with quote

sileence wrote:
Wow, very fast answer. Thank you.

I already replaced the display method, but it doesn't help too much, I think it just creates overhead and inconsistency because I need to specify the .tpl extensions in the other methods anyway, right?

Code:
public function display($template, $cache_id = null, $compile_id = null, $parent = null)
{
  parent::display($template . '.tpl', $cache_id, $compile_id, $parent);
}


This hack will probably cause more problems Smile
Back to top
View user's profile Send private message Visit poster's website
sileence
Smarty n00b


Joined: 14 Nov 2010
Posts: 4

PostPosted: Wed Dec 01, 2010 5:43 pm    Post subject: Reply with quote

That's what I thought. Anyway a good feature could be having a way to configure a default tpl extension, something like:

Code:
$this->setDefaultTemplateExt('tpl')


That way we could avoid having to specify the same extension for every template. Well, I think it'd be nice

***

On a different matter, I extended the Smarty class, and I wonder if it's okay to create magic methods, array access methods to assign or retrieve data, example:

Code:
function __set($var, $value)
{
  $this->assign($var, $value);
}


I really apreciate your help.
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 -> General 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