|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sileence Smarty n00b
Joined: 14 Nov 2010 Posts: 4
|
Posted: Wed Dec 01, 2010 4:35 pm Post subject: Default Extension? |
|
|
{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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Dec 01, 2010 4:38 pm Post subject: |
|
|
#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 |
|
sileence Smarty n00b
Joined: 14 Nov 2010 Posts: 4
|
Posted: Wed Dec 01, 2010 4:48 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Dec 01, 2010 5:11 pm Post subject: |
|
|
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 |
|
Back to top |
|
sileence Smarty n00b
Joined: 14 Nov 2010 Posts: 4
|
Posted: Wed Dec 01, 2010 5:43 pm Post subject: |
|
|
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 |
|
|
|
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
|