9. Text

A text type variable is used to represent and manipulate a sequence of characters.

<?
    var @t: text
    @t := "Hello"
    @t := @t + " there."
    @t := ToUpper(@t)
?>

Postback

Writing a widget that uses a text property is quite straightforward and is likely the easiest type to implement.

<? register input @TextProperty ?>
<input type="text" name="<?attr OutputId(@TextProperty) ?>" value="<?attr @TextProperty ?>">

You don't need to do anything special when using the text type in JavaScript, as it is similar to the String type in JavaScript.

<? register input @TextProperty ?>
<input type="hidden" id="<?attr OutputId(@TextProperty) ?>" name="<?attr OutputId(@TextProperty) ?>">
<? startupscript ?>

    // It is important to use 'js' encoding when outputting the property value in JavaScript blocks.
    let value = <?js @TextProperty ?>;
    value = value.toUpperCase();

    console.log("Result in uppercase:", value);

<? end ?>
<? submitscript ?>

    const el = document.getElementById(<?js OutputId(@TextProperty) ?>);
    
    // Performing a postback with the text property is straightforward.
    el.value = "Hi, can you post me back please? ♡";

<? end ?>

Depending on the encoding format, different outputs are generated. Let's assume a variable var @s: text holds the value ">>> Stan Laurel & Oliver Hardy <<<". The following outputs will be generated:

Encoding
Output

<?= @s ?>

&gt;&gt;&gt; Stan Laurel &amp; Oliver Hardy &lt;&lt;&lt;

<?attr @s ?>

>>> Stan Laurel &amp; Oliver Hardy &lt;&lt;&lt;

<?js @s ?>

">>> Stan Laurel & Oliver Hardy <<<"

<?raw @s ?>

>>> Stan Laurel & Oliver Hardy <<<

Last updated

Was this helpful?