Jump to content

php in templates driving me crazy .......


methos

Recommended Posts

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated