Is Concatenation in Variables supported?

Continuing the discussion from Formatting status and rank:

I have been able to use concatenation for short text. I’m wondering if I can use it to build longer strings? I have a bunch of reports for different status levels. If they are empty I don’t want to see the table header and I want to display some pro-forma text to say “Nothing to see here.”

I thought that I could push everything into a variable then print it at the end. I’m using a counter in the loop, so I tested a simple IF =$counter$= > 0 ELSE and that worked.

<?set "dataTable" = "<table>" ?>
<?nextrec?>
<?set "i" ++ ?>
<?if "=$status$=" eq "0 - Blocked"?>
<?set "dataTable" = "=$dataTable$=<tr class=\"blocked\">" ?>
<?else?>
<?set "dataTable" = "=$dataTable$=<tr>" ?>
<?endif?>
etc
<?loop?>

<?if =$i$= > 0 ?>
=$dataTable$= </table>
<?else?>
<h2>There are no blockers at present</h2>
<?endif?>

Unfortunately, I get nothing in the report. Am I making errors in code or errors in assuming that this is supported behaviour?

To tell the truth, I’ve never tried concatenation before, and I’m guessing it won’t work the way you are wanting it to.

Here’s something that seems to do something similar to what you’re attempting, which does work:

<?output "report.html"?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>Var Concatenation Test</title>
</head>
<body>
<?set i = 0 ?>
<?nextrec?>
<?if "=$status$=" eq "0 - Idea"?>
<?if =$i$= == 0 ?>
<table>
<?endif?>
<?set i ++ ?>
<tr class="blocked"><td>
=$title$= is blocked
</td></tr>
<?endif?>
<?loop?>
<?if =$i$= > 0 ?>
</table>
<?else?>
<h2>There are no blockers at present</h2>
<?endif?>
</body>
</html>

In addition to avoiding concatenation, one change I’ve made here is to initially set your counting variable to a value of zero, to ensure it’s treated as a numeric variable.

Hope this makes sense!

Yes, I get it. You declare the variable within the loop. The loop doesn’t run unless it has a found set, so checking the variable after the loop will tell me whether I have entered the loop, i.e., did the filter return any notes.

It wasn’t working when the string length was thousands. However, it does work for short strings. When I naively used it in a different collection the longest possible string length was always going to be less than 32 characters. It worked reliably there. It would be interesting to know what the limit is. Being able to utilise concatenation, even if it is length limited, is extremely powerful.