Survey list in home page

More
1 month 3 weeks ago #196060 by Andrewsss
Hi, maybe some one can help me with this problem?

Now in home page show all public surveys, but I need group public surveys by categories.

I try to do this in theme file "layout_survey_list.twig" but i don't now what to change.

{% for key, oSurvey in aSurveyInfo.publicSurveys %}

<li class="{{ aSurveyInfo.class.surveylistrowdivbdivulli }} btn-group col-sm-6 col-xs-12" {{ aSurveyInfo.attr.surveylistrowdivbdivulli }}>
<a
href="{{ oSurvey.sSurveyUrl }}"
title="{{ gT("Start survey") }}"
lang="{{ oSurvey.language }}"
class="{{ aSurveyInfo.class.surveylistrowdivbdivullia }} btn btn-primary col-xs-12" >
{{ oSurvey.localizedTitle }}
</a>
</li>
{% endfor %}
</ul>

Maybe possible categorize by survey theme name or survey group name?

Thanks for the HELP.

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #196090 by tpartner
Replied by tpartner on topic Survey list in home page
I don't see the survey group available in layout_survey_list.twig but the theme name is available so you could group the surveys by theme name.

Replace the <ul> element in layout_survey_list.twig with something like this:

{# Create an array of the theme names #}
{% set aThemes = [] %}
{% for oSurvey in aSurveyInfo.publicSurveys %}
	{% if oSurvey.template not in aThemes %}
		{% set aThemes = aThemes|merge([oSurvey.template]) %}
	{% endif %}
{% endfor %}
 
{# Loop through the theme names #}
{% for theme in aThemes %}
 
	{% set themeName = theme %}
 
	<h4>{{ themeName }}</h4>
	<ul class='{{ aSurveyInfo.class.surveylistrowdivbdivul }} list-unstyled ' {{ aSurveyInfo.attr.surveylistrowdivbdivul }}>
 
 
 
		{% for key, oSurvey in aSurveyInfo.publicSurveys %}
			{% if oSurvey.template  == themeName %}
				<li class="{{ aSurveyInfo.class.surveylistrowdivbdivulli }} btn-group col-sm-6 col-xs-12" {{ aSurveyInfo.attr.surveylistrowdivbdivulli }}>
					<a
						href="{{ oSurvey.sSurveyUrl }}"
						title="{{ gT("Start survey") }}"
						lang="{{ oSurvey.language }}"
						class="{{ aSurveyInfo.class.surveylistrowdivbdivullia }} btn btn-primary col-xs-12"  >
							{{ oSurvey.localizedTitle }}
					</a>
				</li>
			{% endif %}
		{% endfor %}
 
 
	</ul>
 
{% endfor %}

The result:


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
Last edit: 1 month 3 weeks ago by tpartner.
The following user(s) said Thank You: Andrewsss

Please Log in to join the conversation.

More
1 month 3 weeks ago #196110 by Andrewsss
Replied by Andrewsss on topic Survey list in home page
Thanks for the help you are awesome.

But I have one more question.
Maybe possible make that: show only one selected theme example vanilla?

Please Log in to join the conversation.

More
1 month 3 weeks ago #196135 by tpartner
Replied by tpartner on topic Survey list in home page
Why bother with that? If you only want to show a single sub-set of the surveys, simply turn off the "List survey publicly" setting for all surveys that you don't want shown.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #196137 by Andrewsss
Replied by Andrewsss on topic Survey list in home page
In home page I want create 2 buttons. one button redirect to page with vanila theme surveys other button redirect to other theme surveys.

For that I need show only one theme surveys in page.
Last edit: 1 month 3 weeks ago by Andrewsss.

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #196144 by tpartner
Replied by tpartner on topic Survey list in home page
It seems to me that something like this will give you a list of the vanilla themed surveys and a list of the non-vanilla themed surveys.

<h4>Vanilla</h4>
<ul class='{{ aSurveyInfo.class.surveylistrowdivbdivul }} list-unstyled ' {{ aSurveyInfo.attr.surveylistrowdivbdivul }}>
	{% for key, oSurvey in aSurveyInfo.publicSurveys %}
		{% if oSurvey.template  == 'vanilla' %}
			<li class="{{ aSurveyInfo.class.surveylistrowdivbdivulli }} btn-group col-sm-6 col-xs-12" {{ aSurveyInfo.attr.surveylistrowdivbdivulli }}>
				<a
					href="{{ oSurvey.sSurveyUrl }}"
					title="{{ gT("Start survey") }}"
					lang="{{ oSurvey.language }}"
					class="{{ aSurveyInfo.class.surveylistrowdivbdivullia }} btn btn-primary col-xs-12"  >
						{{ oSurvey.localizedTitle }}
				</a>
			</li>
		{% endif %}
	{% endfor %}
</ul> 
<h4>Other Themes</h4>
<ul class='{{ aSurveyInfo.class.surveylistrowdivbdivul }} list-unstyled ' {{ aSurveyInfo.attr.surveylistrowdivbdivul }}>
	{% for key, oSurvey in aSurveyInfo.publicSurveys %}
		{% if oSurvey.template  != 'vanilla' %}
			<li class="{{ aSurveyInfo.class.surveylistrowdivbdivulli }} btn-group col-sm-6 col-xs-12" {{ aSurveyInfo.attr.surveylistrowdivbdivulli }}>
				<a
					href="{{ oSurvey.sSurveyUrl }}"
					title="{{ gT("Start survey") }}"
					lang="{{ oSurvey.language }}"
					class="{{ aSurveyInfo.class.surveylistrowdivbdivullia }} btn btn-primary col-xs-12"  >
						{{ oSurvey.localizedTitle }}
				</a>
			</li>
		{% endif %}
	{% endfor %}
</ul>

Then, maybe Bootstrap collapse to hide/show the lists.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 1 month 3 weeks ago by tpartner.
The following user(s) said Thank You: Andrewsss

Please Log in to join the conversation.

More
1 month 3 weeks ago #196145 by Andrewsss
Replied by Andrewsss on topic Survey list in home page
Thanks. With this code I can use only default theme yes? User extended or created themes I can't use. I try with vanilla and works perfect but when I change to fruity show only other themes.

Please Log in to join the conversation.

More
1 month 3 weeks ago #196148 by Joffm
Replied by Joffm on topic Survey list in home page
But tpartner answered exactly to your question

one button redirect to page with vanila theme surveys other button redirect to other theme


Therefore you should always explain very precisely what you are going to achieve.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
1 month 3 weeks ago #196151 by tpartner
Replied by tpartner on topic Survey list in home page
Yeah, I don't understand what the request is now.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Please Log in to join the conversation.

More
1 month 3 weeks ago #196162 by Andrewsss
Replied by Andrewsss on topic Survey list in home page
I mean it possible change vanilla theme to extended theme? Like example instead of vanilla show extends_fruity2 themes surveys.

Please Log in to join the conversation.

More
1 month 3 weeks ago #196165 by tpartner
Replied by tpartner on topic Survey list in home page
Errr....simply replace the theme name in the code I provided.

{% if oSurvey.template  == 'extends_fruity2' %}

{% if oSurvey.template  != 'extends_fruity2' %}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: Andrewsss

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #196166 by Joffm
Replied by Joffm on topic Survey list in home page
Didn't you try to change the line
{% if oSurvey.template == 'vanilla' %}
to
{% if oSurvey.template == 'extended_vanilla' %}
to see what happens?

Or extend the script to the templates you want to display?
{% if oSurvey.template == 'extended_vanilla' %}
...
{% if oSurvey.template == 'extended_fruity' %}
...
{% if oSurvey.template == 'my_very_special_template' %}
...

and for all others:
{% if oSurvey.template != 'extended_vanilla' and oSurvey.template != 'extended_fruity' and oSurvey.template != 'my_very_special_template' %}

[/u]


And furthermore you could try some javascript functions like
str.indexOf("extended") to get all templates that contain "extended" in their name.
https://www.w3schools.com/jsref/jsref_indexof.asp

I did not test this last idea, because I am not familiar at all with javascript.
But I am able to play around with a given snippet.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 1 month 3 weeks ago by Joffm.
The following user(s) said Thank You: Andrewsss

Please Log in to join the conversation.

More
1 month 3 weeks ago #196170 by tpartner
Replied by tpartner on topic Survey list in home page

And furthermore you could try some javascript functions like
str.indexOf("extended") to get all templates that contain "extended" in their name.

Creating the separate lists with JavaScript would be a different (but viable) approach than the pure TWIG solution outlined above.

If you want to use JavaScript, you will need to place an attribute in the <li> elements so the JS can identify them.

Something like:

<li class="{{ aSurveyInfo.class.surveylistrowdivbdivulli }} btn-group col-sm-6 col-xs-12" {{ aSurveyInfo.attr.surveylistrowdivbdivulli }} data-theme="{{ oSurvey.template }}">

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: Andrewsss

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #196173 by Joffm
Replied by Joffm on topic Survey list in home page
Sorry,
I was confused a bit.
In that moment I did not realize that it is twig, not javascript.

So I think you can use:

{% if 'extend' in oSurvey.template %} resp. {% if 'extend' not in oSurvey.template %}



Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 1 month 3 weeks ago by Joffm.

Please Log in to join the conversation.

More
1 month 3 weeks ago #196179 by Andrewsss
Replied by Andrewsss on topic Survey list in home page
Thanks for the help, you helped a lot.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now