Welcome to the LimeSurvey Community Forum

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

Access LS Variable in Javascript (custom.js)

  • BlackSwan
  • BlackSwan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 days 15 hours ago #267140 by BlackSwan
Please help us help you and fill where relevant:
Your LimeSurvey version: CE 6.6.6
Own server or LimeSurvey hosting: own
Survey theme/template: fruity_twentythree
==================
I have some questions about Custon Javascript and the Twig variables:

1. Did I understand correctly that in the Custom.js the LS variables are not directly addressable but in the question-text they are??

2. is it a viable way to output the variables via twig instead and then read them into JS?

3. i have tried Twig solution, but am not getting anywhere in parts:

<div id=“SurveyName” style='display:none' hidden=1>{{ aSurveyInfo.name }}</div>
<div id=“QuestionNumber” style='display:none' hidden=1>{{ aQuestion.questionNumber }}</div>
<div id=“NumberOfQuestions” style='display:none' hidden=1>{{ aSurveyInfo.questioncount }}</div>
<div id=“NumberOfQuestions” style='display:none' hidden=1>{{ aSurveyInfo.numberofquestions }}</div>

Only the survey name is displayed here. What is the correct variable name of the other two variables? Where can I find the documentation for the twig variables? 
 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 days 15 hours ago #267141 by tpartner
Replied by tpartner on topic Access LS Variable in Javascript (custom.js)
1. Yes.

2. Yes, I frequently load twig or ExpressionScript variables into hidden inputs and then retrieve them in custom.js.

3. Try dumping the aSurveyInfo array.
Code:
{{ dump(aSurveyInfo) }}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • BlackSwan
  • BlackSwan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 days 14 hours ago #267144 by BlackSwan
Replied by BlackSwan on topic Access LS Variable in Javascript (custom.js)
Thanks for the quick reply. that brings light into the darkness.

However, if I add
Code:
<div id=“VariableNames” style='display:none' hidden=1>{{ dump(aSurveyInfo) }}</div>
to my Twig file, the div remains empty. Is this due to the scope of the mainrow.twig ? Or am I doing something wrong?

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 days 12 hours ago #267148 by tpartner
Replied by tpartner on topic Access LS Variable in Javascript (custom.js)
I'm not sure what is available in that file. Try it in layout_global.twig.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • BlackSwan
  • BlackSwan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 days 12 hours ago - 4 days 11 hours ago #267151 by BlackSwan
Replied by BlackSwan on topic Access LS Variable in Javascript (custom.js)
I tried it with no success. I added at line 121

Code:
                {# Bootstrap alert modal #}
                {{ include('./subviews/messages/bootstrap_alert_modal.twig') }}
 
                <div id='VariableNames' style='display:block'>{{ dump(aSurveyInfo) }}</div>
 
                {# Basic ThemeScript options  #}


But the div stays empty. Do you have any idea?
Last edit: 4 days 11 hours ago by BlackSwan.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 days 10 hours ago #267155 by tpartner
Replied by tpartner on topic Access LS Variable in Javascript (custom.js)
In config.php, you need to set debug to 1 or 2.

 

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • BlackSwan
  • BlackSwan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 days 4 hours ago - 4 days 4 hours ago #267159 by BlackSwan
Replied by BlackSwan on topic Access LS Variable in Javascript (custom.js)
Thanks Tony,
that was the trick. Anyway, I got 944 pages of variables and am having a hard time figuring out the right ones.
But with “processString()” I was able to read all the information. Probably there is a more direct way without processString() but this way I have everything I need.

Code:
{{ aSurveyInfo.name }}
{{ aSurveyInfo.iTotalquestions }}

I have not found an equivalent for these
Code:
{{ processString('{NUMBEROFQUESTIONS}') }}
{{ processString('{self.qseq}') }}

It would certainly be helpful if the most important ones were documented somewhere. It looks like the twig-overview it's still a work in progress.

You made my day. Thanks for the quick help!
Last edit: 4 days 4 hours ago by BlackSwan.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose