Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Ok, it's probably me, but I can't make this work as I expect.

I have data in a page (entered via a databound form). It's bookings for an event, with standard and student tickets available. I want to output a table of all bookings, with totals at the bottom (an overall total and totals for each type of ticket)

The 'student_ticket' and 'standard_ticket' fields are validated as 'decimal', so should be valid numbers for arithmetic purposes.

Here's what I'm doing:

Code: Select all
  <cms:set student_total '0' scope='global'/>
  <cms:set standard_total '0' scope='global'/>
  <cms:set total '0' scope='global' />
  <table class='table'>
    <tr><th>Name</th><th>Email</th><th>Standard</th><th>Student</th></tr>
    <cms:pages masterpage='booking.php'>
      <tr>
        <td><cms:show booking_name /></td>
        <td><cms:show email /></td>
        <td><cms:show standard_tickets /></td>
        <td><cms:show student_tickets /></td>
      </tr>
      <cms:set standard_total = "<cms:add standard_total standard_tickets />" />
      <cms:set student_total = "<cms:add student_total student_tickets />" />
    </cms:pages>
    <cms:set total = "<cms:add student_total standard_total />" />
    <tr>
      <td><strong>Totals</strong></td>
      <td><cms:show total /></td>
      <td><cms:show standard_total /></td>
      <td><cms:show student_total /></td>
    </tr>
  </table>


Although I have several rows of test data in there, and the names, emails and numbers of tickets appear in the table correctly, the value returned by <cms:show total /> is zero, and the other two table cells which should contain totals are empty. The final table row is output as:
Code: Select all
<tr>
      <td><strong>Totals</strong></td>
      <td>0</td>
      <td></td>
      <td></td>
  </tr>


What's going on? (or to be more accurate, isn't going on!)
Hi,

You have defined the initial variables with 'global' scope.
While setting them later on, if you don't specify the scope they'll get set in the current scope (which happens to be of cms:pages in this case).

Please add the correct scope in the later statements e.g. as follows
Code: Select all
<cms:set standard_total = "<cms:add standard_total standard_tickets />" scope='global' />
<cms:set student_total = "<cms:add student_total student_tickets />" scope='global' />
<cms:set total = "<cms:add student_total standard_total />" scope='global' />

Hope it helps.
Thanks, KK, as always!

I'd read it that the 'cms:set' was setting both the value and the scope, and assumed that the scope was then a set attribute of the variable.

May I suggest adding the sentence 'Once it has been included, the scope needs to be included every time the variable is set' to the documentation?
3 posts Page 1 of 1
cron