Welcome to the LimeSurvey Community Forum

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

Dynamically render Survey Group styling based upon flag or variable

  • aellison9
  • aellison9's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #194174 by aellison9
If I wanted to pass a query string variable to a survey indicating which survey group to use for rendering the survey, is it possible to then dynamically process the variable and render the survey with the correct look and feel?

I understand there may be development involved which is ok, just looking for the best approach to take.

The easiest example I can think of for this question is "light" mode versus "dark" mode. For users who prefer light mode, we would render surveys on a light back ground. Conversely, for users who prefer dark mode, we would render surveys on a black background with light lettering.

Light versus dark is just a simplistic example. For our potential use case, we might have 4 or more survey groups that could be selected as a preference.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #194177 by tpartner
You can prefill a hidden (via question setting) question with a URL parameter - manual.limesurvey.org/URL_fields/en#Pref...using_GET_parameters

(for example's sake, let's use a hidden list-radio with question code "control")

Having done that...

1) For styling, you can apply a class to the <body> element by extending the theme and modifying the <body> tag in layout_global.twig something like this:
Code:
<body class="control-{{ processString('{control}') }} {{ aSurveyInfo.class.body }} font-{{  aSurveyInfo.options.font }} lang-{{aSurveyInfo.languagecode}} {{aSurveyInfo.surveyformat}} {% if( aSurveyInfo.options.brandlogo == "on") %}brand-logo{%endif%}" {{ aSurveyInfo.attr.body }} >

2) For survey content, you can use question and/or group relevance based on the hidden question to hide/show various survey elements.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • aellison9
  • aellison9's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #194204 by aellison9
TPartner, thank you for the reply.

I currently have PHP code that extracts query string parameters from the inbound URL and stores the values in session so I have access to them throughout a survey. This lets me know what the desired "look and feel" parameter should be without having to us a hidden question on every survey constructed.

I could write a bunch of CSS classes to be used for each look and feel but I was hoping to utilize the current structures in LimeSurvey which already accomplish Theming.

I was hoping for an extensible way to "swap" the "light" survey group for the "default" survey group when the survey request is made. Maybe it's a pipe dream and the only way is to re-write all the CSS available within the SurveyGroup but I am ever the optimist.

Thank you again for your reply. I do appreciate your time and willingness to help.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose