Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Token display: formatting

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 9 months ago #242597 by vzyldd
Token display: formatting was created by vzyldd
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community Edition   Version 5.6.7+230222
Own server or LimeSurvey hosting: Yes
Survey theme/template: Fruity
==================
I need to display the token (13 characters) on the first page of the survey for verification by the surveyor. I used {{ processString('{TOKEN:TOKEN}') }} in a TWIG file (head.twig) - thank you Tony - for the display.

How do I display it in a larger font size?
Is it possible to display it in the following format (000-00000-00-0-0-0)?

Thank you

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago - 1 year 9 months ago #242659 by tpartner
Replied by tpartner on topic Token display: formatting

How do I display it in a larger font size?

Wrap it in a <span> (or other element) which you can apply styles to.

Is it possible to display it in the following format (000-00000-00-0-0-0)?

Someone may have a more elegant way to do this, but if you are self-hosted you can add the TWIG slice filter to your config.php file and then use it in the TWIG file to extract and combine segments of the token into your format.

Something like this in /application/config/config.php:

Code:
  'components' => array(
    'db' => array(
      'connectionString' => 'mysql:host=localhost;port=3306;dbname=limesurvey;',
      'emulatePrepare' => true,
      'username' => 'username',
      'password' => 'password',
      'charset' => 'utf8mb4',
      'tablePrefix' => 'lime_',
    ),
 
     'session' => array (
      'sessionName'=>'LS-SMRVRMDZUKTSFGRQ',
      // Uncomment the following lines if you need table-based sessions.
      // Note: Table-based sessions are currently not supported on MSSQL server.
      // 'class' => 'application.core.web.DbHttpSession',
      // 'connectionID' => 'db',
      // 'sessionTableName' => '{{sessions}}',
     ),
 
    'urlManager' => array(
      'urlFormat' => 'path',
      'rules' => array(
        // You can add your own rules here
      ),
      'showScriptName' => true,
    ),
 
    'twigRenderer' => array(
      'sandboxConfig' => array(
        'filters' => array(
          'slice',
        ),
      ),
    ),
 
  ),

Then, something like this in the TWIG file:

Code:
{% set token = processString('{TOKEN}') %}
{% set t1 = token|slice(0, 3) %}
{% set t2 = token|slice(3, 5) %}
{% set t3 = token|slice(8, 2) %}
{% set t4 = token|slice(10, 1) %}
{% set t5 = token|slice(11, 1) %}
{% set t6 = token|slice(12, 1) %}
{% set formattedToken = t1~'-'~t2~'-'~t3~'-'~t4~'-'~t5~'-'~t6 %}
<span style="font-size: 1.3em;">{{ formattedToken }}</span>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 year 9 months ago by tpartner.

Please Log in to join the conversation.

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 9 months ago #242674 by vzyldd
Replied by vzyldd on topic Token display: formatting
Thank you Tony. As always, saving the day. Much appreciated.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose