methos Posted April 15, 2007 Share Posted April 15, 2007 Hi all, I am having a headache here whilst trying to create a customised order form template. I used to be halfway proficient a php a few years back, but I have never come across this style of code within curly braces that is used in the templates and trying to get it to do what i want is driving me crazy. I am trying to increment a counter variable within the main loop of the first order form template and the code snippet i am using is shown below. My problem is that everytime I increment the value of $cnt (using $cnt++) it actually prints the value of $cnt to the html output - what the heck am i doing wrong? here is a simplified version of the code (the output extra columns are simply there so i can test the value of $cnt whilst building it) - the first time through the loop it is fine and creates my extra column and tells me $cnt eq 1, but then every other time through it not only does that but echo's the value before incremnting back to the actual html output. How can I stop this echo? {$cnt = 0} {foreach key=num item=product from=$products} <table width="98%"> <tr> <td > <form method="post" action="{$smarty.server.PHP_SELF}?step=2"> <input type="hidden" name="pid" value="{$product.pid}"> [b]{$product.name}[/b] {$product.description} <input type="hidden" name="billingcycle" value="monthly"> <input type="submit" value="{$LANG.ordernowbutton}"> { $cnt++ } </form> </td> {if $cnt eq 1} <td>extra column after 1</td> {/if} {if $cnt eq 2} <td>extra column after 2</td> {/if} {if $cnt eq 3} <td>extra column after 3</td> {/if} {if $cnt eq 4} <td>extra column after 4</td> {/if} {if $cnt eq 5} <td>extra column after 5</td> {/if} </tr> </table> {/foreach} thanks, Tony 0 Quote Link to comment Share on other sites More sharing options...
methos Posted April 15, 2007 Author Share Posted April 15, 2007 well, i've solved the initial problem by using $num since it is already being incremented as part of the loop, but i am still puzzled as to how to increment another variable without having it print. 0 Quote Link to comment Share on other sites More sharing options...
Adam Posted April 15, 2007 Share Posted April 15, 2007 Hey, Use {php} {/php} instead of <?php and ?> as you would normally do in any PHP file. From, Adam 0 Quote Link to comment Share on other sites More sharing options...
skshost Posted April 15, 2007 Share Posted April 15, 2007 Don't feel bad, getting used to smarty takes some time. 0 Quote Link to comment Share on other sites More sharing options...
methos Posted April 15, 2007 Author Share Posted April 15, 2007 thanks ... it took me a while to discover that it actually was smarty - then at least i could look up the reference I've manged to get it doing more or less what i wanted now - example of my order form at : http://tb-hosting.com/services/order.php?gid=0000000005 would appreciate any comments ... Thanks, Tony 0 Quote Link to comment Share on other sites More sharing options...
Dominic Posted April 15, 2007 Share Posted April 15, 2007 I have a love-hate relationship with Smarty Just wish it would display errors rather than give white pages! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.