Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Variable not being set?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
latorreinfo
Smarty n00b


Joined: 13 Sep 2019
Posts: 4

PostPosted: Fri Sep 13, 2019 3:13 pm    Post subject: Variable not being set? Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Sep 13, 2019 5:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
latorreinfo
Smarty n00b


Joined: 13 Sep 2019
Posts: 4

PostPosted: Fri Sep 13, 2019 9:02 pm    Post subject: Reply with quote

$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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sat Sep 14, 2019 12:02 am    Post subject: Reply with quote

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
View user's profile Send private message
latorreinfo
Smarty n00b


Joined: 13 Sep 2019
Posts: 4

PostPosted: Sat Sep 14, 2019 9:04 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Sep 14, 2019 9:41 am    Post subject: Reply with quote

Smarty 2 use template function to assign variables:

Code:
{assign var='variable' value=value}


Smarty 3 allows a shorter construction to assign variables:

Code:
{$variable=value}


Speaking of which, if you have the choice, I suggest upgrading your Smarty library.
Back to top
View user's profile Send private message
latorreinfo
Smarty n00b


Joined: 13 Sep 2019
Posts: 4

PostPosted: Sat Sep 14, 2019 9:50 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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