View previous topic :: View next topic |
Author |
Message |
Olin Smarty n00b
Joined: 23 Oct 2008 Posts: 4
|
Posted: Thu Oct 23, 2008 5:18 pm Post subject: |
|
|
very usefool thanks a lot !!! |
|
Back to top |
|
Siskohh Smarty n00b
Joined: 26 Oct 2008 Posts: 3
|
Posted: Sun Oct 26, 2008 6:03 am Post subject: |
|
|
This is the the structure of my array:
Code: |
Array
(
[0] => Array
(
[id] => 1
[parent] => 0
[name] => vati
[children] => Array
(
[0] => Array
(
[id] => 3
[parent] => 1
[name] => sohn1
[children] => Array
(
)
)
[1] => Array
(
[id] => 4
[parent] => 1
[name] => sohn2
[children] => Array
(
)
)
)
)
[1] => Array
(
[id] => 2
[parent] => 0
[name] => mutti
[children] => Array
(
[0] => Array
(
[id] => 5
[parent] => 2
[name] => tochter1
[children] => Array
(
)
)
[1] => Array
(
[id] => 6
[parent] => 2
[name] => tochter2
[children] => Array
(
[0] => Array
(
[id] => 7
[parent] => 6
[name] => tochtertochter
[children] => Array
(
)
)
)
)
)
)
)
|
How would I go about using this plugin to format that array to something like this:
-> vati
----> sohn1
----> sohn2
-> mutti
----> tochter1
----> tochter2
---------> tochtertochter
And even farther, sub childs within sub childs... etc.
I'd tried:
<ul>
<% defun name="testrecursion" list=$Sitemap %>
<% foreach from=$data2 item=element %>
<li><% $element.id %>
<% if $element.element %>
<ul><% fun name="testrecursion" list=$element.element %></ul>
<% /if %>
</li>
<% /foreach %>
<% /defun %>
</ul>
Bt that just gives me forums 1 and 4 and no sub forums.
What am I doing wrong? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Oct 26, 2008 6:06 am Post subject: |
|
|
you should foreach from=$list not from=$data2 (untested), |
|
Back to top |
|
Siskohh Smarty n00b
Joined: 26 Oct 2008 Posts: 3
|
Posted: Sun Oct 26, 2008 6:12 am Post subject: |
|
|
you are right messju, i've changed it. but it doesn't fixed my problem..
Code: |
<div style="background-color: #FFCC99">
Test:<br />
<ul>
{defun name="testrecursion" list=$Sitemap}
{foreach from=$list item=element}
<li>{$element.name}</li>
{if $element.element}
<ul>{fun name="testrecursion" list=$element.element}</ul>
{/if}
{/foreach}
{/defun}
</ul>
</div>
|
is giving me out this:
Code: |
<div style="background-color: rgb(255, 204, 153);">
Test:<br>
<ul>
<li>vati</li>
<li>mutti</li>
</ul>
</div>
|
mhh |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Oct 26, 2008 8:26 am Post subject: |
|
|
And you have to recurse into $element.children not $element.element, obviously. |
|
Back to top |
|
Siskohh Smarty n00b
Joined: 26 Oct 2008 Posts: 3
|
Posted: Sun Oct 26, 2008 9:49 pm Post subject: |
|
|
you are the best it has geklappt! |
|
Back to top |
|
kalleplom Smarty Rookie
Joined: 23 Sep 2006 Posts: 6 Location: berlin
|
Posted: Mon Jan 25, 2010 9:51 am Post subject: |
|
|
This is just the article i was looking for, but i got stuck...:
I copied the codes into the named file and left it all like it is. When trying to compile the HTML is stops with the following:
Code: | Fatal error: Using $this when not in object context in ....\%%30^301^3018A601%%sectionlist.tpl.php on line 48 |
i'm using smarty 2.6.22 and am not that good in programming smarty core functions.. as you see ..
thank you so much for your help and this great contribution! |
|
Back to top |
|
scuzzy Smarty Regular
Joined: 31 Aug 2003 Posts: 84
|
Posted: Tue Jan 26, 2010 11:10 pm Post subject: |
|
|
This will be a PHP error and not a smarty one, ensure you dont have any $this->whatevers() outside of a class. |
|
Back to top |
|
kalleplom Smarty Rookie
Joined: 23 Sep 2006 Posts: 6 Location: berlin
|
Posted: Wed Jan 27, 2010 6:36 am Post subject: |
|
|
hi!
Yes, you're right. This is a php-error, of course. It is in the compiled php file smarty generated.
So there must be an error in the script above, or something doesn't match with the smarty version i'm using.
Code: | <?php if (!function_exists('smarty_fun_testrecursion')) {
function smarty_fun_testrecursion(&$this, $params) {
$_fun_tpl_vars = $this->_tpl_vars;
$this->assign($params); ?>
<?php $_from = $this->_tpl_vars['list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
foreach ($_from as $this->_tpl_vars['element']):
?> |
The first error appears in $_fun_tpl_vars = $this->_tpl_vars;
Because you can't use $this in the function scope. When I change the arguments function smarty_fun_testrecursion(&$this, $params) to
function smarty_fun_testrecursion(&$smarty, $params) and all calls to $smarty->... in the compiled file it works fine.
But what to change in the smarty plug-in? |
|
Back to top |
|
alex Smarty Rookie
Joined: 03 Sep 2005 Posts: 19 Location: Argentina
|
Posted: Mon Feb 15, 2010 9:56 am Post subject: compiler.defun.php and Smarty 3 |
|
|
Hi,
does anybody know if it's possible to use the compiler.defun plugin with Smarty 3, and if so, what modifications need to be done?
In a first test with Smrty 3 I got the following error message:
Fatal error: Call to undefined method Smarty_Internal_SmartyTemplateCompiler::_parse_attrs() in /path/to/my/application/smarty/plugins/compiler.defun.php on line 26
So it seems like the _parse_attrs method isn't available anymore in Smarty 3. Any ideas?
Thanks,
Alex |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Feb 15, 2010 4:22 pm Post subject: |
|
|
Plugins which do make use of Smarty2 internal functions will not run without modification in Smarty3.
However Smarty3 does provide the functionallity of the defun compiler plugin by the {function...} tag. Please see the README. |
|
Back to top |
|
alex Smarty Rookie
Joined: 03 Sep 2005 Posts: 19 Location: Argentina
|
Posted: Mon Feb 15, 2010 10:14 pm Post subject: |
|
|
U.Tews wrote: | However Smarty3 does provide the functionallity of the defun compiler plugin by the {function...} tag. Please see the README. |
That's interesting, thank you! |
|
Back to top |
|
alex Smarty Rookie
Joined: 03 Sep 2005 Posts: 19 Location: Argentina
|
Posted: Tue Feb 16, 2010 10:42 am Post subject: |
|
|
Hi again,
I tested the new {function}...{/function} block tag and it worked fine. However it seems to be slower than the defun compiler plugin.
I use it for the tree structured threads of this web forum. With Smarty 2.6.26 and the compiler defun plugin the elapse time of the index page is about 0.03 s (local webserver). Smarty 3.0 Beta 7: about 0.2 s. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Feb 16, 2010 9:17 pm Post subject: |
|
|
Do you have force_compile=false?
The Smarty3 compiling process is slower than in Smarty2 but once the templates are compiled the rendering times should be almost the same. |
|
Back to top |
|
alex Smarty Rookie
Joined: 03 Sep 2005 Posts: 19 Location: Argentina
|
Posted: Wed Feb 17, 2010 10:12 am Post subject: |
|
|
U.Tews wrote: | Do you have force_compile=false? |
I didn't set force_compile so it should be false (default).
Here is a little demonstration script:
http://www.mediafire.com/?emvmfrwman2
You can switch between Smarty 2 and 3 and the elapse time is displayed at the bottom of the page. The folders templates_c_2 and templates_c_3 need to be writable. |
|
Back to top |
|
|