Welcome to the LimeSurvey Community Forum

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

Survey list in home page

  • Andrewsss
  • Andrewsss's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months ago #196060 by Andrewsss
Survey list in home page was created 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.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months 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:

Code:
{# 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.
Last edit: 3 years 11 months ago by tpartner.
The following user(s) said Thank You: Andrewsss
The topic has been locked.
  • Andrewsss
  • Andrewsss's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months 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?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months 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.
The topic has been locked.
  • Andrewsss
  • Andrewsss's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months ago - 3 years 11 months 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: 3 years 11 months ago by Andrewsss.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months 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.

Code:
<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.
Last edit: 3 years 11 months ago by tpartner.
The following user(s) said Thank You: Andrewsss
The topic has been locked.
  • Andrewsss
  • Andrewsss's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months 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.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months 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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months 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.
The topic has been locked.
  • Andrewsss
  • Andrewsss's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months 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.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months 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.

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

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

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: Andrewsss
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months 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' %}




And furthermore you could try some javascript functions like
str.indexOf("extended") to get all templates that contain "extended" in their name.
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
Last edit: 3 years 11 months ago by Joffm.
The following user(s) said Thank You: Andrewsss
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose