Inline script

In an Askia survey, an inline script is a string evaluated by the AskiaScript engine. It can be inserted almost anywhere in an Askia survey, for example  in a question caption, response caption, page label, page settings (header, footer, buttons, etc.).

EAS (Embed AskiaScript)

Like many template page engines (ASP, PHP, ERB, EJS...), Askia allows you to embed AskiaScript into any string or HTML output. EAS is the new inline script engine which gives more flexibility and many more possibilities than the previous engine. It provides a way to control the flow of the interpreted script (execute only, execute and write the result, or execute and write the resulting encoded html).

Syntax

Askia offers a backwards-compatible syntax which surrounds the script with a pair of double exclamation marks (!! script !!), and a more classical syntax with {% script %} (in version 2.0 onwards). We recommend that you use {% %}, in order to control the flow of the interpreted script.

!! _askia_script_ !!      ' -> Execute the script and write the result (Raw HTML????)
{% _askia_script_ %} ' -> Execute the script without output
{%= _askia_script_ %} ' -> Execute the script and write the result (HTML Encoded in order to avoid XSS attack
{%:= _askia_script_ %} ' -> Execute the script and write the result (Raw HTML)

 

Examples

String injection with EAS:

Change the background color according to the respondent gender

  <div style="background: {%= on(gender Has {1}, "blue", "pink") %}"> [Content] </div>

  <!-- 'Same as : -->

  <div style="background: !! on(gender Has {1}, "blue", "pink") !!"> [Content] </div>

String injection, the HTML content will be escaped:

  <div>

      {%= "a < b > c" %}

  </div>

HTML Code Rendering:

   <div>

         a &lt; b &gt; c

   </div>

String injection, the HTML content will NOT be escaped (with colon before the equal sign):

  <div>

      {%:= "a < b > c" %}

   </div>

HTML Code Rendering:

   <div>

         a < b > c

   </div>

 

HTML injection with EAS:

  {%:= on(gender Has {1}, "<img src="guy.png" />", "<img src="girls.png" />") %}

Render the image, take care about the colon before the equal sign. Without the colon it will escape the HTML string

Conditional output with EAS:

  {% If gender Has {1} And age < 18 Then %}

            Hi guys!

  {% ElseIf gender Has {1} And age >= 18  Then %}

            Hello gentleman!

  {% ElseIf gender Has {2} And age < 18 Then %}

            Hi girls!

  {% ElseIf gender Has {2} And age >= 18 Then %}

           Hello ladies!

  {% Else %}

            Hello!

  {% EndIf %}

When gender = 2 and age = 17, output:

     Hi girls!

 

Programmatic loop with EAS:

 {% dim i = 1

      For i = 1 To 3

  %}

         Iterate {%= i %} times!<br />

  {% Next %}

 

Output:

     Iterate 1 times!

     Iterate 2 times!

     Iterate 3 times!
Create your own Knowledge Base