Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

strange behavior of section

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
ubat
Smarty n00b


Joined: 12 Aug 2003
Posts: 3

PostPosted: Tue Aug 12, 2003 11:54 pm    Post subject: strange behavior of section Reply with quote

Hi !

I am encountering a strange behavior of the section-tag. after months of working perfectly all of a sudden the section-tag would produce its output twice. i will give a simple excample, which behaves exactly the same as my original, complex array.

an array like

$myAr[] = "Hello";
$myAr[] = "Test";
$myAr[] = "One";

will show like

Hello
Test
One
Hello
Test
One

I am working on a rather complex system, so i can not tell all the circumstances in this thread, but may be someone had the same problem.

my section looks like that

{$section name=i loop=$myAr}
{$myAr[i]}<br>
{$/section}

best regards !
Back to top
View user's profile Send private message Send e-mail
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Aug 13, 2003 6:49 am    Post subject: Reply with quote

Code:
{$section name=i loop=$myAr}
{$myAr[i]}<br>
{$/section}


The code you posted is definitly wrong. It should look like this
Code:
{section name=i loop=$myAr}
{$myAr[i]}<br>
{/section}


{section} ... {/section} is a block function. Therefore you shouldn't add a dollar sign ($) infront of the tag names.
Back to top
View user's profile Send private message
ubat
Smarty n00b


Joined: 12 Aug 2003
Posts: 3

PostPosted: Wed Aug 13, 2003 5:41 pm    Post subject: uhhh Reply with quote

i am really sorry, but of course this is a typing mistake, as i was posting the thread in the middle of the night, wehen i had been coding for about 4 hours.

of course the syntax in my project is correct.

here ist my testcode from the project :
Code:

$test[] = "Hallo";
$test[] = "Ein";
$test[] = "Test";


and here is my section

Code:

{section name=i loop=$test}
{$test[i]}
{/section}


and here is my result :

Hallo Ein Test Hallo Ein Test

may be it helps to know, that i have a template with some kind of framework for the website, in which i include a variable content-template.
the section is then in the content-template. may be smarty mixes up something. but i really didnt have this problem before.

like

Code:

<td>

{include file=$seitenInhalt}

</td>


where $seitenInhalt can be different .tpl-files, depending, how the variable was set by the calling php-script.

thanx
Back to top
View user's profile Send private message Send e-mail
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Aug 13, 2003 5:57 pm    Post subject: Reply with quote

Hi ubat:

Yeah, I thought that it must have been a syntax error if it was working previously Wink I thought I would wait to see how you responded to andre, though (hi andre).

Quick Q:

- what does a print_r($test) look like and/or what does the Smarty Debug Console say about $test's contents? or how about count($test) -- how many elements in the source array?

It almost looks like you are using a db abstraction layer that is returning both associative and indexed values (thereby duplicating all elements).

Quote:
after months of working perfectly all of a sudden the section-tag would produce its output twice

What really happened to your code-base between the "working perfectly" and "all of a sudden"?

Clearly, the code you posted is not on its own responsible for the issue you are experiencing.

One last thing: the dynamic include in your last post--is that in a loop?
Back to top
View user's profile Send private message
ubat
Smarty n00b


Joined: 12 Aug 2003
Posts: 3

PostPosted: Thu Aug 14, 2003 3:46 pm    Post subject: Reply with quote

hi again !

i finally found out, what caused the problem.

i was including my .php-file in another html-php-mixed file. because this was an old file ( not created by me - i don't like mixing html/php ), i commented the whole thing out and manipulated a copy of the content beneath the out-commented part.

of course php ignores the
Code:
<!-- -->
, so my file was included twice, once in the outcommented part and once in my working part, and as it was a pure php-file, it filled my arrays twice.

so this post is just to let everybody know of my blindness and that my problem is solved Smile.

take care !
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP