|
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 |
Lord Micro Smarty n00b
Joined: 05 Dec 2004 Posts: 4 Location: Ramenskoye
|
Posted: Sun Dec 05, 2004 8:51 am Post subject: Why in Smarty there is no support of blocks? |
|
|
Up to Smarty I used own patterns (on logic HTML_Template_Sigma from package PEAR). I very much like idea of support of numerous hierarchical blocks of a HTML-code. I shall result an example from own class of patterns:
Example #1:
index.php :
Code: |
// Init my class
$tpl = new HTML_Template_MT(".");
// Load template file with hierarchical blocks of a HTML-code
$tpl->loadTemplatefile("template.html")
// I define, that further work will be made with this block
$tpl->setCurrentBlock("block1");
// Set variable
$tpl->setVariable("test","test value");
// Close work with block
$tpl->parseCurrentBlock();
// Display HTML-page
$tpl->show();
|
template.html :
Code: |
<!-- BEGIN block1 -->
This is a block
Variable test value: {test}
<!-- END block1 -->
This not into block.{test}
|
OUTPUT:
Code: |
This is a block
Variable test value: {test}
This is not block.
|
Example #2:
index.php :
Code: |
$tpl = new HTML_Template_MT(".");
$tpl->loadTemplatefile("template.html")
$tpl->setVariable("test","test value");
$tpl->parse("block1");
// Display HTML-page
$tpl->show();
|
template.html :
Code: |
<!-- BEGIN block1 -->
This is a block
Variable test value: {test}
<!-- END block1 -->
This not into block.{test}
|
OUTPUT:
Code: |
This is a block
Variable test value: {test}
This is not block.
|
Example #3:
index.php :
Code: |
$tpl = new HTML_Template_MT(".");
$tpl->loadTemplatefile("template.html")
$tpl->setVariable("test","test value");
$tpl->touchBlock("block1");
// Display HTML-page
$tpl->show();
|
template.html :
Code: |
<!-- BEGIN block1 -->
This is a block
Variable test value: {test}
<!-- END block1 -->
This not into block.{test}
|
OUTPUT:
Code: |
This is a block
Variable test value: {test}
This is not block.test value
|
Example #4:
index.php :
Code: |
$tpl = new HTML_Template_MT(".");
$tpl->loadTemplatefile("template.html")
$tpl->setCurrentBlock("block1");
$tpl->setVariable("test","test value");
$tpl->setCurrentBlock("block1");
$tpl->parse("block1");
$tpl->setVariable("intotest","intotest value");
$tpl->touchBlock("thisblock");
$tpl->parseCurrentBlock();
$tpl->setVariable("test2","test2 value");
$tpl->parseCurrentBlock();
// Display HTML-page
$tpl->show();
|
template.html :
Code: |
<!-- BEGIN block1 -->
This is a block1
Variable test value: {test}
Variable test2 value: {test2}
<!-- BEGIN block1 -->
<!-- BEGIN thisblock -->
This is intotest var: {intotest}
<!-- END thisblock -->
This is too intotest var: {intotest}
<!-- END block1 -->
<!-- BEGIN block2 -->
This is block2!
<!-- END block2 -->
The end of block1
<!-- END block1 -->
This not into block.{test}
|
OUTPUT:
Code: |
This is a block1
Variable test value: test value
Variable test2 value: test2 value
This is intotest var: intotest value
This is too intotest var: intotest value
This is block2!
The end of block1
This not into block.test value
|
The idea described would be higher remarkable addition to Smarty. How you think? |
|
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
|