- Posts: 23
- Thank you received: 6
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
- Topic Author
- Offline
- Junior Member
Less
More
4 years 1 month ago #194174
by aellison9
Dynamically render Survey Group styling based upon flag or variable was created 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.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10629
- Thank you received: 3696
4 years 1 month ago #194177
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Dynamically render Survey Group styling based upon flag or variable
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:
2) For survey content, you can use question and/or group relevance based on the hidden question to hide/show various survey elements.
(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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 6
4 years 1 month ago #194204
by aellison9
Replied by aellison9 on topic Dynamically render Survey Group styling based upon flag or variable
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.
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.