|
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 |
ilyalyu Smarty Regular
Joined: 03 Nov 2009 Posts: 72
|
Posted: Sat Nov 17, 2012 3:50 pm Post subject: Smarty inheritance |
|
|
1.
Feature request: template methods (similar to class methods in c++, php, etc)
1.a. Allow to override template method in child template
1.b. Allow to define template method outside of any block
Code: | Sample:
template a.html:
{method 'f'}1{/method}
{f}
template b.html:
{extends 'a.html'}
{method 'f'}2{/method}
b.html output: 2 |
====================
2.
I already tried to explain this in another topic. Consider the following samples:
Code: | Sample 1:
class a { function f() { return 1; } }
class b extends a { function f() { return parent::f() . 2; } }
class c extends b { function f() { return 3 . parent::f(); } }
$obj = new b(); echo $obj->f(), '<br>';
$obj = new c(); echo $obj->f(), '<br>';
Output:
12
312
Sample 2:
class b { function f() { return 12; } }
class c extends b { function f() { return 3 . parent::f(); } }
$obj = new b(); echo $obj->f(), '<br>';
$obj = new c(); echo $obj->f(), '<br>';
Output:
12
312
Sample 3:
a.html: {block 'content'}1{/block}
b.html: {extends 'a.html'}{block 'content' append}2{/block}
c.html: {extends 'b.html'}{block 'content' prepend}3{/block}
b.html output: 12
c.html output: 132
Sample 4:
b.html: {block 'content'}12{/block}
c.html: {extends 'b.html'}{block 'content' prepend}3{/block}
b.html output: 12
c.html output: 312 |
The first two samples are written in PHP. Class b in sample 1 and sample 2 is implemented in a different way. However, the output is the same in both samples independent of class b implementation details. This is one of the main advantages of OOP that you can use class without thinking about its internal implementation.
The other two samples are written in Smarty. As you can see, the output of template c.html DEPENDS on the implementation of template b.html. When I use {block 'content' prepend}3{/block} code I can't predict the result without looking into the implementation details of template b.html. The figure "3" may be added before "12", but it can be also be inserted between "1" and "2" or it can be added after "12". I don't know this until I look into b.html template.
When I work in PHP, I can change the implementation of class b without the risk of breaking the outside program and I can use class b methods without thinking about class b implementation. I.e. what is inside class b is isolated from what is outside class b.
When I work in Smarty, I can't use template b.html without looking into template b.html code and I can't change template b.html implementation without the risk of breaking the outside code. |
|
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
|