recursion in template possible?

Author Message

Michael D.

Wednesday 12 October 2005 2:17:15 am

Hello there.

I wonder if recursion is/will be possible within a template.

What I tried as a test was:
<i>test.tpl</i>

{default test=0}
    {$test}+
    {section show=$test | lt(5)}
        {include uri="design:test.tpl" test=$test|inc}
        {set test=$test|dec}
    {/section}
    {$test}-
{/default}

output: 0+ 1+ 2+ 3+ 4+ 5+ 5- 4- 3- 3- 3- 3-

I would expect it to work like this:
<i>test2.tpl</i>

{default test2=0}
    {*0*}
    {$test2}+
    {set test2=$test2|inc}
        {*1*}    
        {$test2}+
        {set test2=$test2|inc}
            {*2*}    
            {$test2}+
            {set test2=$test2|inc}
                {*3*}    
                {$test2}+
                {set test2=$test2|inc}
                    {*4*}    
                    {$test2}+
                    {set test2=$test2|inc}
                        {*5*}    
                        {$test2}+
                        {*backstepping begins*}
                        {$test2}-
                    {set test2=$test2|dec}
                    {$test2}-
                {set test2=$test2|dec}
                {$test2}-
            {set test2=$test2|dec}
            {$test2}-
        {set test2=$test2|dec}
        {$test2}-
    {set test2=$test2|dec}
    {$test2}-
{/default}

output: 0+ 1+ 2+ 3+ 4+ 5+ 5- 4- 3- 2- 1- 0-

The second template is my idea of the transition from recursive to iterative but the recursion seems to work very different.

Is there a chance this behaviour will be changed in the future or am I hoping for the impossible (due to the nature of the internal handling of this)?

Thanks, Michael

Alexandre Abric

Wednesday 12 October 2005 6:53:48 am

Hi,

That's strange : I used the same template with eZ Publish 3.6.1 and I got the expected result.

0+ 1+ 2+ 3+ 4+ 5+ 5- 4- 3- 2- 1- 0-

What version did you use ?

Michael D.

Wednesday 12 October 2005 7:16:17 am

Sorry, I forgot to mention: It's eZ publish 3.6.1 svn rev. 12063.

I'm including it in the pagelayout.tpl, could that make a difference?
It's the first include and there is no other var named "test" in the pagelayout.tpl.

Settings are:
TemplateCompile=enabled
ViewCaching=disabled
TemplateCache=enabled

The rest is default or not listed because I don't think they are important in this matter. If some are, please let me know and I'll post them here.

Alexandre Abric

Monday 17 October 2005 5:27:20 am

I think there should be a difference if you included the code in the pagelayout.tpl

For the test, I created a folder called "TEST RECURSION", created an override for the full view of the node, and added the code you provided.

Michael D.

Monday 17 October 2005 6:08:32 am

I tried your way with the node override but I'm still getting the same (undesirable) result.

I'll try to make a clean ez 3.6 install and test it there as well as on another system.

Hopefully this will bring me closer to the solution.
Since your response indicates this, there has to be a way to make it work.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 01:19:19
Script start
Timing: Jan 19 2025 01:19:19
Module start 'layout'
Timing: Jan 19 2025 01:19:19
Module start 'content'
Timing: Jan 19 2025 01:19:19
Module end 'content'
Timing: Jan 19 2025 01:19:19
Script end

Main resources:

Total runtime0.0159 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0044 590.6016152.6250
Module start 'layout' 0.00440.0042 743.226639.4609
Module start 'content' 0.00860.0050 782.687593.3359
Module end 'content' 0.01350.0023 876.023434.3047
Script end 0.0159  910.3281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003018.7826140.0002
Check MTime0.001811.3758140.0001
Mysql Total
Database connection0.00063.994410.0006
Mysqli_queries0.002616.462230.0009
Looping result0.00000.195010.0000
Template Total0.001911.710.0019
Template load0.00116.631410.0011
Template processing0.00085.039910.0008
Override
Cache load0.00063.875910.0006
General
dbfile0.00021.564580.0000
String conversion0.00000.075040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs