By: David
Date: 2013-02-20
Time: 23:33
|
OpenTBS displaying variable instead of evaluating where
I have an OpenTBS template with the following:
[customerblock;when [var.num_cust]+-0;block=begin][ customerblock.name]
[customerblock.description][customerblock;block=end]
|
The PHP used looks like this:
$num_cust=0;
$query = "SELECT * from customers WHERE company_id = '$company_id' ORDER BY print_order";
if ($result = mysqli_query($link, $query)) {
while ($customer = mysqli_fetch_assoc($result)) {
$num_cust++;
$customer_array[] = Array('name' => $customer['name'], 'description' => $customer['description']);
}
}
.... more code here ...
$TBS->VarRef['num_cust'] = $num_cust;
$TBS->MergeBlock('customerblock', $customer_array);
|
I expect that if there no customers in the file $num_cust will be 0 and the section will not print but I get this:
[customerblock;block=begin;when 0+-0][ customerblock.name]
[customerblock.description][customerblock;block=end]
|
I have tried using block=w:p+w:p instead of block=begin and block=end, moving the when between the customerblock; and the ;block= in the first OpenTBS tag and a few other things. Why does the when print the value of num_cust instead of just not printing the block?
Thanks,
David
|
By: Sarah
Date: 2013-02-21
Time: 00:19
|
Re: OpenTBS displaying variable instead of evaluating where
Do you have a space before your blockName in any of your tags? I see you have one in [ customerblock.name], which will cause that not to merge, and when I tried your situation, I was able to get the var.num_cust to merge and the surrounding customerblock to not merge (your result) by having a space prior to customerblock and after the [
I can tell you that the code you show:
[customerblock;block=begin;when [var.num_cust]+-0][customerblock.name]
[customerblock.description][customerblock;block=end]
|
Works properly for me (though I tested with a subblock not a block), so I don't think your problem is with the placement of the 'when', or with the begin and end block declarations.
|
By: David
Date: 2013-02-21
Time: 02:00
|
Re: OpenTBS displaying variable instead of evaluating where
I've tried cutting and pasting the code you posted back as working, using paste -> special ->unformatted text to make sure it wasn't an XML character I couldn't see. That didn't work. I also tried changing += to != but just get [customerblock;block=begin;when 0!=0]. I'm going to keep trying.
|
By: David
Date: 2013-02-21
Time: 02:41
|
Re: OpenTBS displaying variable instead of evaluating where
I don't know why, but I changed it back to
[onload;block=w:p+w:p;when [var.num_cust]!=0][customerblock.name]
[customerblock.description]
|
and it works!!
I am very happy and moving on to the next challenge.
|
|
Posting in progress.
Please wait...
|