|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
latorreinfo Smarty n00b
Joined: 13 Sep 2019 Posts: 4
|
Posted: Fri Sep 13, 2019 3:13 pm Post subject: Variable not being set? |
|
|
I'm totally new to Smarty - I'm using a php generator that uses Smarty. I am trying to modify the generated tpl file. I need to store the 'round number' for the row so I can compare it with the next row and on a change throw a page break in the html print.
The code is below - I have diagnostics in it and every time it runs $Prev (where I store the value) is blank on every output line.
What am I going wrong
{$Prev = 1}
<table class="wide text-center">
<tr>
{foreach item=Column from=$Columns}
<td><b>{$Column->GetCaption()}</b></td>
{/foreach}
</tr>
{foreach item=Row from=$Rows name=RowsGrid}
<tr>
{foreach item=RowColumn from=$Row}
<td>
{$RowColumn}
</td>
{/foreach}
{* the next 2 lines are for testing only*}
<td>{$Prev}</td>
<td>{$Row.0}</td>
{$Prev = $Row.0}
</tr>
{/foreach}
{include file='list/totals.tpl'}
</table |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Fri Sep 13, 2019 5:58 pm Post subject: |
|
|
Is $Row an array? It seems to be.
If so, then instead of $Row.0, try using $Row[0]. (The dot-syntax may be specific to associative arrays - string keys, not plain indexed arrays.) |
|
Back to top |
|
latorreinfo Smarty n00b
Joined: 13 Sep 2019 Posts: 4
|
Posted: Fri Sep 13, 2019 9:02 pm Post subject: |
|
|
$Row is an associative array and isn't the problem
The problem is line 1
{$prev = 1}
If I immediately display using {$prev} is shows blank and not 1 as I would expect |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sat Sep 14, 2019 12:02 am Post subject: |
|
|
Please verify if you are using Smarty 2 or Smarty 3.
Smarty 2 does not use the short-hand syntax that Smarty 3 allows.
Try:
Code: | {assign var='Prev' value=1}
{$Prev} |
|
|
Back to top |
|
latorreinfo Smarty n00b
Joined: 13 Sep 2019 Posts: 4
|
Posted: Sat Sep 14, 2019 9:04 am Post subject: |
|
|
I've loooked and it appears to be release 2 (version 2.6.26).
Please can you explain more what the short hand is
THanks |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Sep 14, 2019 9:41 am Post subject: |
|
|
Smarty 2 use template function to assign variables:
Code: | {assign var='variable' value=value} |
Smarty 3 allows a shorter construction to assign variables:
Speaking of which, if you have the choice, I suggest upgrading your Smarty library. |
|
Back to top |
|
latorreinfo Smarty n00b
Joined: 13 Sep 2019 Posts: 4
|
Posted: Sat Sep 14, 2019 9:50 am Post subject: |
|
|
thanks, I dont have a choice re smarty release as it comes with embedded in sqlmaestro phpgenerator and they are shipping it with release 2 |
|
Back to top |
|
|
|
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
|