- Posts: 57
- Thank you received: 1
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
-
Topic Author
- Offline
- Senior Member
-
Less
More
3 years 2 months ago - 3 years 2 months ago #212816
by sodiumchl
How to get the survey description in twig was created 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.
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 2 months ago by sodiumchl.
The topic has been locked.
- DenisChenu
-
- Offline
- LimeSurvey Community Team
-
Less
More
- Posts: 13716
- Thank you received: 2502
3 years 2 months ago #212827
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
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
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 service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- sodiumchl
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 1
3 years 2 months ago - 3 years 2 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:
{{ 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.)
I see in SurveysController.php that publicSurveys is from
Any more help is appreciated.
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 2 months ago by sodiumchl.
The topic has been locked.
- DenisChenu
-
- Offline
- LimeSurvey Community Team
-
Less
More
- Posts: 13716
- Thank you received: 2502
3 years 2 months ago #212870
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
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 ?
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 service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- sodiumchl
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 1
3 years 2 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.
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
-
Topic Author
- Offline
- Senior Member
-
Less
More
- Posts: 57
- Thank you received: 1
3 years 2 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:
Why don't we expose the big array $aSurveyInfo this way? Any cons?
Code:
public function getDescription() { $sLanguage = isset(App()->language)? App()->language: $this->language; $aSurveryInfo = getSurveyInfo($this->sid, $sLanguage); if (isset($aSurveryInfo) && 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
-
- Offline
- LimeSurvey Community Team
-
Less
More
- Posts: 13716
- Thank you received: 2502
3 years 2 months ago #212936
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
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 ?
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 service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: sodiumchl
The topic has been locked.