Reply to Updating a variable, in a TPL file?

Your name:

Reply:


Posted by Arthur Dent on 04/15/06 05:17

Hello all, sorry for the cross-post, but im not sure which group is best for
this question.

I am an ASP.NET developer, but am learning PHP/perl for the first time now
to make some to changes to a client's site which was done by someone else.

I wrote a debug TPL which ive got working great now and was Such a sense of
accomplishment!! :) . People always say how cryptic C can be, but i think
perl definitely beats C out! Anyway.... In the
/classes/com/<site>/runtime/Page.class.php i have some code which reads
whether the user has requested debug mode and presets some variables for the
debug.tpl i wrote. Here is the code i have in my Page.class file:

$smarty->assign("wantdebug","0");
if(isset($_REQUEST['debug'])){
$smarty->assign("wantdebug","1");

$smarty->assign("sesobj",$_SESSION);
< above line repeated for $_PUT, $_GET and $_COOKIE >
}

The following code is the code of my debug.tpl. Everything from the opening
B tag to the final BR tag is repeated over for the $_PUT, $_GET and $_COOKIE
smarty variables set up in the Page.class.

{if $wantdebug}
<div style="background-color: white; border: solid 1px black;
padding=3px;">
<b style="cursor: hand;"
onclick="javascript:document.all['lblSession'].style.display=(document.all['lblSession'].style.display=='none')?'':'none';">&lt;session&gt;</b>
<label id='lblSession' style="display: none;"><br>
{foreach from="$sesobj" key="key" item="value"}
&nbsp;&nbsp;&nbsp;&nbsp;{$key}=={$value|replace:"<br>":"|"}<br>
{foreachelse}
&nbsp;&nbsp;&nbsp;&nbsp;no session items<br>
{/foreach}
<b>&lt;/session&gt;</b>
</label><br>
</div>
{/if}

This all works fine and dandy, and the "<session>" text in the B tag acts as
a nice little toggle switch to hide show the array contents, like the way
the little +/- signs do in IE when viewing a raw XML file.

Now here comes my problem.... I want to include the TPL at both the top and
the bottom of my pages, so that i can see the contents of all the variables
before and after the page has done all its processing to see how things have
been affected. But now when i refer to document.all['lblSession'] there are
two of them on the page. So what i want to do is to have a variable which i
can append to the label tag's id attribute to make unique ids, such as
"lblSession1" and "lblSession2". How can i do this? I though i could create
a variable in the Page.class code, then use it in the TPL something like
id='lblSession{$MyID}' . Then update the variable in each inclusion of
the header so each time through the label's ID would be unique based on this
variable, but i cant seem to get the variable to update. What i tried are
the couple following things, but none worked.....
any help how to do this? Thanks in advance!!!

1st tried:
<label id='lblSession{$MyID++}' style="display: none;">

2nd tried:
{if $wantdebug}
..... code omitted, from block included above ................

{php}
$MyID++
{/php}
{/if}

3rd tried:
{if $wantdebug}
..... code omitted, from block included above ................

{php}
$smarty->assign("MyID",$MyID+1)
{/php}
{/if}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация