- Posts: 11
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Insert line break in string
- lwolters
- Topic Author
- Offline
- New Member
Less
More
9 years 4 months ago #114879
by lwolters
Insert line break in string was created by lwolters
I have Q1, Q2 and Q3 all ask for a certain symptom to be present, yes or no. Then I have a hidden question Q4, which constructs a string like this:
{if(Q1 == 'Y', 'symptom 1<br />',''}{if(Q2 == 'Y', 'symptom 2<br />',''}{if(Q3 == 'Y', 'symptom 3<br />','')}
The next couple of questions recall the string constructed in Q4, i.e. Q5: 'The symptoms are:{Q4.NAOK}'
Now, if the questions are displayed on the same page, in Q5 etc. every <br /> gives a line break as wanted. But I need the questions to be displayed one by one and then the <br/> does not insert a line break but is literaly displayed as part of the string.
I also tried to use the \n in combination with nl2br(), but this does'nt work at all.
Can anyone please help me out?
{if(Q1 == 'Y', 'symptom 1<br />',''}{if(Q2 == 'Y', 'symptom 2<br />',''}{if(Q3 == 'Y', 'symptom 3<br />','')}
The next couple of questions recall the string constructed in Q4, i.e. Q5: 'The symptoms are:{Q4.NAOK}'
Now, if the questions are displayed on the same page, in Q5 etc. every <br /> gives a line break as wanted. But I need the questions to be displayed one by one and then the <br/> does not insert a line break but is literaly displayed as part of the string.
I also tried to use the \n in combination with nl2br(), but this does'nt work at all.
Can anyone please help me out?
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
9 years 4 months ago #114881
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 Insert line break in string
Try using HTML entities and the entity_decode() function -
manual.limesurvey.org/Expression_Manager#Access_to_Functions
.
Code:
{if(Q1 == 'Y', html_entity_decode('symptom 1&lt;br /&gt;'), '')}{if(Q2 == 'Y', html_entity_decode('symptom 2&lt;br /&gt;'), '')}{if(Q3 == 'Y', html_entity_decode('symptom 3&lt;br /&gt;'), '')}
.
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: lwolters
The topic has been locked.
- lwolters
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
9 years 4 months ago #114937
by lwolters
Replied by lwolters on topic Insert line break in string
Thanks for your reply. I tried this solution but again the HTML-tag is literally shown. The output is:
The symptoms are symptom 2<br />symptom 3<br />
The symptoms are symptom 2<br />symptom 3<br />
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
9 years 4 months ago - 9 years 4 months ago #114940
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 Insert line break in string
Working survey attached.
Try disabling the WYSIWYG editor when modifying that question. Perhaps the editor is converting the HTML entities back to tags.
Try disabling the WYSIWYG editor when modifying that question. Perhaps the editor is converting the HTML entities back to tags.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 9 years 4 months ago by tpartner.
The topic has been locked.
- lwolters
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
9 years 4 months ago #114950
by lwolters
Replied by lwolters on topic Insert line break in string
Thanks for your help again. My problem is that when (in your sample questionnaire) you make boilerPlate1 an (hidden) equation and then recall boilerPlate1 in later questions, the linebreaks have been disappeared. I'd like to recall 'boilerPlate1' because there is a number of questions where I need a list of symptoms and in the real questionnaire this list is quiet long.
I attached my testsurvey.
I attached my testsurvey.
Attachments:
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
9 years 4 months ago - 9 years 4 months ago #114984
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 Insert line break in string
Okay, how about this?
1) Place something like this in your equation question (let's call it equation1):
2) And where you want to display it:
New sample survey:
1) Place something like this in your equation question (let's call it equation1):
Code:
{if(Q1 == 'Y', htmlentities('symptom 1<br />'), '')}{if(Q2 == 'Y', htmlentities('symptom 2<br />'), '')}{if(Q3 == 'Y', htmlentities('symptom 3<br />'), '')}
2) And where you want to display it:
Code:
{html_entity_decode(equation1)}
New sample survey:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 9 years 4 months ago by tpartner.
The following user(s) said Thank You: lwolters
The topic has been locked.
- lwolters
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
9 years 4 months ago #114985
by lwolters
Replied by lwolters on topic Insert line break in string
It works ! Thank you very much for your help.
best regards,
Liselot
best regards,
Liselot
The topic has been locked.