Welcome to the LimeSurvey Community Forum

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

How to get the survey description in twig

  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 9 months ago - 3 years 9 months ago #212816 by sodiumchl
How can I get the survey description in twig for a list of active surveys?
I tried the following. But neigher oSurvey.description nor oSurvey.localizedDescription works.
Code:
{% for oSurvey in aSurveyInfo.publicSurveys %}
     <li>
         {{ oSurvey.localizedTitle }} - {{ oSurvey.description }}
     </li>
{% endfor %}
Last edit: 3 years 9 months ago by sodiumchl.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 9 months ago #212827 by DenisChenu
Replied by DenisChenu on topic How to get the survey description in twig
Try with {{ dump(aSurveyInfo) }}

And : look at existing twig file

github.com/LimeSurvey/LimeSurvey/blob/72...ges/welcome.twig#L34

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 9 months ago - 3 years 9 months ago #212858 by sodiumchl
Replied by sodiumchl on topic How to get the survey description in twig
With {{ processString(oSurvey.description,1) }} I got the following error:
Code:
An exception has been thrown during the rendering of a template ("Survey and its behaviors do not have a method or closure named "description".") in "__string_template ..."

{{ dump(aSurveyInfo) }} gives me the following. But oSurvey.localizedTitle and oSurvey.sSurveyUrl work fine. (I am doing this in layout_survey_list.twig of a custom theme.) 
Code:
{
  "publicSurveys": [   // <== this is oSurveys
    {
      "searched_value": null,
      "showsurveypolicynotice": "0"
    },
    {
      "searched_value": null,
      "showsurveypolicynotice": "0"
    },
    ...
    {
      "searched_value": null,
      "showsurveypolicynotice": "0"
    }
  ],
  "futureSurveys": ,
  "oTemplate": {
  ...
}
 

I see in SurveysController.php that publicSurveys is from
Code:
'publicSurveys'     => Survey::model()->active()->open()->public()->with('languagesettings')->findAll()

Any more help is appreciated.
 
Last edit: 3 years 9 months ago by sodiumchl.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 9 months ago #212870 by DenisChenu
Replied by DenisChenu on topic How to get the survey description in twig
{{ processString(oSurvey.description,1) }} != {{ processString(aSurveyInfo.description,1) }}

You really read : github.com/LimeSurvey/LimeSurvey/blob/72...ges/welcome.twig#L34 ?
 

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 9 months ago #212912 by sodiumchl
Replied by sodiumchl on topic How to get the survey description in twig
Well, aSurveyInfo in welcome.twig is a single survey, whereas aSurveyInfo in layout_survey_list.twig contains an array of publicSurveys and an array of futureSurveys. Each item of the arrays is an array, oSurvey above, with a title and a description.

I just need to add a short description to the list of available surveys. I also tried
{{oSurvey.surveyinfo.description}} which did not work either.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 9 months ago #212919 by sodiumchl
Replied by sodiumchl on topic How to get the survey description in twig
I found that if I add the following to application/models/Survey.php, then {{ oSurvey.description }} works:
Code:
    public function getDescription()
    {
        $sLanguage = isset(App()->language)? App()->language: $this->language;
        $aSurveryInfo = getSurveyInfo($this->sid, $sLanguage);
        if (isset($aSurveryInfo) &amp;&amp; isset($aSurveryInfo['description'])) return $aSurveryInfo['description'];
        return 'no description available';
    }

Why don't we expose the big array $aSurveyInfo this way? Any cons?
 
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 9 months ago #212936 by DenisChenu
Replied by DenisChenu on topic How to get the survey description in twig
Argl … sorry didn't see where you need it ... really sorry.

You can add twig function with plugin i think . But maybe here , best is to use your own controiller to do the home page ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The following user(s) said Thank You: sodiumchl
The topic has been locked.
Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose