| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| en:create:functions:gettextelement [02.12.2014 19:59] – [Example 2] alexander.ritter | en:create:functions:gettextelement [23.10.2026 14:44] (current) – external edit 127.0.0.1 |
|---|
| ====== getTextElement() ====== | ====== getTextElement() ====== |
| |
| ''string **getTextElement**(string //textID//)'' | The function ''getTextElement()'' returns the content of a text (text element or text in the list of questions) as a string. |
| |
| Returns the HTML code for the text element with the ID //textID// as a string. | The optional second parameter can either (only) set the output format or specify additional settings and placeholders. |
| |
| * //textID//\\ ID of the text element whose content is to be returned. | ''string **getTextElement**(string //textID//, [string //outputFormat//])'' |
| | |
| | ''string **getTextElement**(string //textID//, array //settings//)'' |
| | |
| | * //textID//\\ ID of the text element whose content shall be returned. |
| | * //outputFormat// |
| | * Optionally, you can specify in which format the content is returned. |
| | * ''%%'block'%%'' -> (default) HTML code in a block element (with spacing and alignment) |
| | * ''%%'html'%%'' -> Only the actual content as HTML code |
| | * ''%%'plain'%%'' -> Unformatted text with line breaks |
| | * Or you can retrieve a specific content of the text element (as unformatted plain text) |
| | * ''%%'header'%%'' -- Heading |
| | * ''%%'content'%%'' -- Content without heading |
| | * ''%%'title'%%'' -- Title or question text in the display "like a question" |
| | * ''%%'explanation'%%'' -- Explanations/instructions |
| | * //settings//\\ Optionally, settings and placeholders can be defined |
| | * ''%%'format'%%'' -> Output format as above |
| | * ''%%'%key%'%%'' -> Placeholders that are replaced in the text element before output |
| | |
| | **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. |
| |
| **Note:** If the text element is output in the questionnaire with a title and/or formatting, this is also included in the HTML code. However, the potential alignment (left/centred/right/justified) and the spacing below the text element are not included. | |
| |
| ===== Example 1 ===== | ===== Example 1 ===== |
| |
| In the following example, one of 2 text elements ("desc1" or "desc2") is integrated into a third placeholder ("description") via placeholder. The third text element therefore must contain the placeholder ''%desc%''. | 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%''. |
| |
| <code php> | <code php> |
| if (value('AB01_01') == 1) { | if (value('AB01_01') == 1) { |
| $desc = getTextElement('desc1'); | $desc = getTextElement('desc1', 'html'); |
| } else { | } else { |
| $desc = getTextElement('desc2'); | $desc = getTextElement('desc2', 'html'); |
| } | } |
| replace('%desc%', $desc); | replace('%desc%', $desc); |
| text('description'); | text('description'); |
| </code> | </code> |
| | |
| |
| ===== Example 2 ===== | ===== Example 2 ===== |
| |
| In the following example, each "a" and "A" is replaced with an underscore and the text element subsequently displayed. | In the following example, each "a" and each "A" is replaced with an underscore, and the text element is subsequently displayed. |
| |
| <code php> | <code php> |
| html($out); | html($out); |
| </code> | </code> |
| | |
| | |
| | ===== Example 3 ===== |
| | |
| | Here, a text ''TX01'' with the display "HTML code" was defined, which contains several placeholders: |
| | |
| | <code html> |
| | <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> |
| | </code> |
| | |
| | This text element is used several times in the questionnaire, and the placeholders are filled differently each time, e.g. |
| | |
| | <code php> |
| | $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); |
| | </code> |
| | |