Forums / Setup & design / recursion in template possible?

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.