View previous topic :: View next topic |
Author |
Message |
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Mar 27, 2009 6:54 pm Post subject: |
|
|
Okay no big deal to change it. will do it tomorrow. |
|
Back to top |
|
yankee Smarty Rookie
Joined: 02 Mar 2009 Posts: 31
|
Posted: Fri Mar 27, 2009 7:08 pm Post subject: |
|
|
Reading this text I thought of a new type of {assign}-Statement like this:
{assign var='foo'}bar{/assign}
Note that the value of $foo does not come from a value attribute, but from code within the function. Internally this could be done by using php's output buffering functions.
This architecture allows something like this:
Code: | {assign var='head'}<!-- put css /javascript stuff here -->{/assign}
{assign var='body'}<!-- put content here -->{/assign}
<html>
<head>
{$head}
</head>
<body>
{$body}
</body>
</html> |
Of course the obove assign code can come from an included template. And it could be made possible to write down the inclusion chain in the controller:
Code: |
$head =$smarty->createTemplate('head.tpl');
$body =$smarty->createTemplate('body.tpl');
$out =$smarty->createTemplate('master.tpl');
$out->addPreRun($head);
$out->addPreRun($body);
$out->display(); |
This should give more possibilities to the user while decreasing the complexity of smarty's language...
And one more thing:
Code: | $smarty->display('extend:base.tpl|foo.tpl'); |
This is a language within a language. The problems that come with it are already known to us by other languages that work like that (for example SQL).
I'd prefer to write such things in php.. Either like this:
Code: | $smarty->extend('array('foo.tpl', 'bar.tpl', 'foobar.tpl')); |
Or by something that looks similar to the "addPreRun"-Code above. |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Fri Mar 27, 2009 7:29 pm Post subject: |
|
|
yankee,
capture seems to do the same thing as the assign you mentioned
http://www.smarty.net/manual/en/language.builtin.functions.php#language.function.capture
every one,
I was wondering if {block}s can be nested in the superclass. I realize this makes things more complicated to implement, but at the same time, it could allow the user to change the entire page, or change things on a smaller granularity.
Problem is, I don't think nesting would make sense in a subclass, I don't know.
perhaps there could be two functions, block (for super-templates) and block_replace (for sub-templates)
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 27, 2009 8:06 pm Post subject: |
|
|
Quote: | I was wondering if {block}s can be nested in the superclass. I realize this makes things more complicated to implement, but at the same time, it could allow the user to change the entire page, or change things on a smaller granularity. |
I don't think that will happen. You are correct, it gets too complex. I think you can build your templates with building blocks that extend each other to get the combination you want.
A lot of the feature inspiration came from django and there is probably a reason why they don't nest them either. |
|
Back to top |
|
yankee Smarty Rookie
Joined: 02 Mar 2009 Posts: 31
|
Posted: Fri Mar 27, 2009 8:21 pm Post subject: |
|
|
douglassdavis wrote: | yankee,
capture seems to do the same thing as the assign you mentioned |
Yes, you are right... At least it's nearly the same.
douglassdavis wrote: | I was wondering if {block}s can be nested in the superclass. I realize this makes things more complicated to implement, but at the same time, it could allow the user to change the entire page, or change things on a smaller granularity. |
Well... You could do this using variables . |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Fri Mar 27, 2009 9:17 pm Post subject: |
|
|
yankee wrote: | douglassdavis wrote: |
douglassdavis wrote: | I was wondering if {block}s can be nested in the superclass. I realize this makes things more complicated to implement, but at the same time, it could allow the user to change the entire page, or change things on a smaller granularity. |
Well... You could do this using variables . |
|
You can do many things with variables... But, explain how please.
From what I'm thinking, some one could do something like:
base.tpl
Code: |
{block name='sentence'}The {block name='color'}brown{/block} fox jumped over the dog.{/block}
|
my.tpl
Code: |
{block name='color'}red{/block}
|
Produces:
Code: |
The red fox jumped over the dog.
|
So, from that the user can choose to change the entire sentence OR the color of the fox when the template is inherited. I can think of a few things I've done where this would be useful.
The problem is if some one did not nest the same in a sub-template, I'm not sure what the meaning would be:
Code: |
{block name='color'}Some text{block name='sentence'}more stuff{/block} the last bit{/block}
|
My interpretation would be similar to in PHP when A() calls B(), and you subclass it, override A() and B() and make B() call A(). but, i could see how it could be trouble. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Mar 27, 2009 11:23 pm Post subject: |
|
|
Nesting of blocks is not allowed for good reasions.... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Mar 28, 2009 8:53 am Post subject: |
|
|
The file order has been changed:
Code: | Smarty->display('extend:base.tpl|section.tpl|my.tpl');
|
|
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Jun 09, 2009 8:43 pm Post subject: |
|
|
so..
can a super template include other templates?
if so, presumably included files would be in the same dir as the super-template? how would that happen, since the template dir is that of the sub-template?
would a new template dir be established within the super-template as soon as you do an {extend}? That is, if I make a super template, can i count on the template dir to be the same as the super-template's dir?
Otherwise, how do includes in the super-template work? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jun 13, 2009 9:25 pm Post subject: |
|
|
The super template (base.tpl) can include other templates. The template_dir is use same way as on any other template. |
|
Back to top |
|
v2k Smarty n00b
Joined: 13 Oct 2009 Posts: 1
|
Posted: Tue Oct 13, 2009 2:11 am Post subject: |
|
|
Is there any documentation or examples for using inheritance in smarty 3? Beyond this thread, I can't seem to find anything. |
|
Back to top |
|
onamali Smarty n00b
Joined: 29 Nov 2009 Posts: 2 Location: Malta, EU
|
Posted: Sun Nov 29, 2009 11:35 am Post subject: |
|
|
As of Smarty 3 Beta 5 the correct code for using extends programatically is
Smarty->display('extends:base.tpl|section.tpl|my.tpl');
Please note the resource name is EXTENDS not EXTEND as listed in the previous examples.
Example
index.php
Code: | $page='home'
$smarty=new Smarty();
// Other smarty setup code here
$smarty->display('extends:base.tpl|'.$page.'.tpl');
|
base.tpl
Code: | <html>
<head>
<title>{block name="title"}{/block}</title>
</head>
<body>
{block name="content"}{/block}
</body>
</html>
|
home.tpl
Code: | {block name="title"}Home Page{/block}
{block name="content"}This is the content of the home page{/block}
|
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Nov 29, 2009 6:47 pm Post subject: |
|
|
See also a brief description in the README file. |
|
Back to top |
|
onamali Smarty n00b
Joined: 29 Nov 2009 Posts: 2 Location: Malta, EU
|
|
Back to top |
|
|