Inhaltsverzeichnis

getTextElement()

The function getTextElement() returns the content of a text (text element or text in the list of questions) as a string.

The optional second parameter can either (only) set the output format or specify additional settings and placeholders.

string getTextElement(string textID, [string outputFormat])

string getTextElement(string textID, array settings)

Note: If the text element is displayed in the questionnaire with a title and/or formatting, this is also included in the HTML code. However, a possible alignment (left/centered/right/justified) and the spacing below the text element are not included.

Example 1

In the following example, one of 2 text elements (“desc1” or “desc2”) is included via placeholder into a third text element (“description”). The third text element must contain the placeholder %desc%.

if (value('AB01_01') == 1) {
  $desc = getTextElement('desc1', 'html');
} else {
  $desc = getTextElement('desc2', 'html');
}
replace('%desc%', $desc);
text('description');

Example 2

In the following example, each “a” and each “A” is replaced with an underscore, and the text element is subsequently displayed.

$content = getTextElement('priming');
$out = str_replace(array('a','A'), '_', $content);
html($out);

Example 3

Here, a text TX01 with the display “HTML code” was defined, which contains several placeholders:

<div id="teaser%num%" style="border: 1px solid #AAAAAA; border-radius: 0.5em; padding: 1em; display: flex; flex-direction: row-reverse; gap: 2em; background-color: white; flex-wrap: wrap;">
    <div style="flex: 1 1 30%; text-align: center;">
        <img src="%image%" alt="" style="width: 100%; max-width: 200px;">
    </div>
    <div style="flex: 1 1 250px;">
        <div style="display: flex; gap: 0.6em; margin-bottom: 0.6em; align-items: center;">
            <img src="%source.logo%" style="width: 22px">
            <span>%source.name%</span>
        </div>
        <div style="font-weight: bold; font-size: 125%;">
            %headline%
        </div>
    </div>
</div>

This text element is used several times in the questionnaire, and the placeholders are filled differently each time, e.g.

$html = '<div style="max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 0.7em; padding: 1em;">';
 
$html.= getTextElement('TX01', [
    '%num%' => 1,
    '%image%' => 'image01.jpg',
    '%source.logo%' => 'source07.png',
    '%source.name%' => '24/4 News',
    '%headline%' => 'ABC representatives visit Helsinki, difficult talks expected.',
    'format' => 'html'
]);
 
$html.= '</div>';
 
html($html);