A beta version of CSPro 8.1 was released recently. In the run-up to the release, we will highlight some new features.
For years, CSPro has supported question text fills. Initially these were limited to replacement variables and occurrence labels and were defined like:
Starting with CSPro 7.6, question text moved from RTF format to HTML, and the fill delimiters changed from % to ~~. The above question text was now written as:
Introduced in CSPro 7.7, the templated reporting system introduced enhanced functionality, and any logic expression that evaluated to a number or string could be inserted in ~~ and ~~~ fills:
This templated reporting system introduced new delimiters, <? ?>, that allowed logic to run during report generation without writing to the report directly as happens with the ~~ and ~~~ fills. However, this only applied to reports and not to question text.
Starting with CSPro 8.1, the evaluation of question text supports <? ?>. If you want to dynamically generate question text within a <? ?> block, you can use the QSF special name. For example, the above question text could be rewritten as:
What is the relationship of <? QSF.writeEncoded("%s", NAME); ?>
to the head of household, <? QSF.writeEncoded("%s", NAME(1)); ?>?
</p>
This is not a good use of <? ?>, as using ~~ is cleaner for simple text fills. However, this is very useful for creating tables or other dynamic question text features. For example, this question text displays the names and ages of people already entered in the household (for occurrences 2+):
<?
if curocc() = 1 then
exit;
endif;
?>
<p>The following people have already been entered:</p>
<ul>
<?
do numeric ctr = 1 while ctr < curocc()
QSF.write("<li>");
QSF.writeEncoded("%s (age: %d)", NAME(ctr), AGE(ctr));
QSF.write("</li>");
enddo;
?>
</ul>
It is also possible to mix and match fills. Based on your coding preference, the bullet points could be written using:
<? do numeric ctr = 1 while ctr < curocc() ?>
<li>~~NAME(ctr)~~ (age: ~~AGE(ctr)~~)</li>
<? enddo; ?>
</ul>
This feature, along with the ability to use Markdown in question text, is yet another step in the evolution of CSPro's question text functionality.




