- Posts: 48
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Inserting an image using TOKEN:ATTRIBUTE
- ngolub
- Topic Author
- Offline
- Senior Member
Your LimeSurvey version: LimeSurvey Community Edition Version 6.4.10+240228
Own server or LimeSurvey hosting: Own server
Survey theme/template: bootstrap vanilla
==================
I am designing a survey and have encountered a specific requirement: only some invitation emails must include an image.
Is it possible to implement this using the TOKEN:ATTRIBUTE method?
If it is not, do you have any alternative suggestions for accomplishing this goal?
Thank you for your time and help.
Please Log in to join the conversation.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11660
- Thank you received: 2742
However, your requirement is not 100% clear to me. Is it always the same image for all that should be shown the image or will each participant have a different image?
Where will the image be displayed?
Could it be in a text display question for example? I think this would be the easiest, as you could just create a relevance equation / condition to show this text display question which contains the image based on the entry in your custom token attribute.
I did not read the initial requirments carefully enough.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Please Log in to join the conversation.
- ngolub
- Topic Author
- Offline
- Senior Member
- Posts: 48
- Thank you received: 0
To answer your question: It is always the same image and should be displayed in the invitation email participants receive. Therefore, I want to embed it in the email template between two paragraphs.
For context: I am sending out ca. 400 invitation emails, but only 200 should contain the image.
If I understand you correctly, you are saying I should create a text display question which contains the image (I would need to hide the question so it does not appear in my survey) and then use a relevance equation/condition to display it in the email. Is that correct?
Please Log in to join the conversation.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11660
- Thank you received: 2742
only some invitation emails must include an image.
I was under the impression that we are talking about images in the survey.
But I think it should be also possible to insert that image into the invitation email without any issue.
If I understand you correctly, you are saying I should create a text display question which contains the image (I would need to hide the question so it does not appear in my survey) and then use a relevance equation/condition to display it in the email. Is that correct?
No, now that I became aware of the fact that you were actually talking about an image in the invitation email, this doesn't make sense.
In this case you'd probably have to use expression manager within the email template and use something like this (not tested, just for you to get an idea on the direction to go with):
{if(TOKEN:ATTRIBUTE_1=="Y","<img src='yourimageurl' />", "")}
You could try something like that. No guarantees! Not tested.
Not sure if in the email template "TOKEN:" is necessary.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Please Log in to join the conversation.
- ngolub
- Topic Author
- Offline
- Senior Member
- Posts: 48
- Thank you received: 0
I'll test it and let you know how it works here.
Please Log in to join the conversation.
- ngolub
- Topic Author
- Offline
- Senior Member
- Posts: 48
- Thank you received: 0
So I tried your solution. However, the expression script is not validated correctly, as seen in the images below.
Here is what I used: {if(TOKEN:ATTRIBUTE_1 == "Y", "<img src=" sspgsurveyprd.ethz.ch/upload/surveys/866522/images/BEISPIEL.png " />", "")}
And here is what I see when I validate the ExpressionScript:
Can you help me pinpoint the issue?
Please Log in to join the conversation.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11660
- Thank you received: 2742
{if(TOKEN:ATTRIBUTE_1=="Y","<img src='yourimageurl' />", "")}
Do you notice something? There is " and there is '. You can't use " in both parts, within the expression and within the HTML code, as the second " will always end this part of the expression. So you need to use ' instead of " for the image source, etc. within the html tags.
Also, your URL is not complete. This might cause another issue later.
Something like this should do the trick:
{if(TOKEN:ATTRIBUTE_1 == "Y", "<img src=' https://sspgsurveyprd.ethz.ch/upload/surveys/866522/images/BEISPIEL.png ' />", "")}
When you post code, please always try to use the code tags, that makes it easier to read your code.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Please Log in to join the conversation.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11660
- Thank you received: 2742
next time better post a LSS file with only the relevant parts of the survey, because screenshots never show the whole picture.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Please Log in to join the conversation.
- ngolub
- Topic Author
- Offline
- Senior Member
- Posts: 48
- Thank you received: 0
I did not know that " will always end this part of the expression; I just learned something new.
However, I did notice that you used ' and not ". The problem I face, however, is that when I copy your solution:
{if(TOKEN:ATTRIBUTE_1 == "Y", "<img src=' https://sspgsurveyprd.ethz.ch/upload/surveys/866522/images/BEISPIEL.png ' />", "")}
And paste it here and press OK:
LimeSurvey automatically changes the ' to " without me doing anything.
Please Log in to join the conversation.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11660
- Thank you received: 2742
{if(TOKEN:ATTRIBUTE_1 == "Y", "<img src='https://sspgsurveyprd.ethz.ch/upload/surveys/866522/images/BEISPIEL.png' />", "")}
Probably because of the spaces that came after the '.
And if you use only " then the first " starts the thing and the second one ends it. In your case you would have something like:
{if(TOKEN:ATTRIBUTE_1 == "Y", "<img src="
And after that, of course LS gets confused, because it expects the next information for the function. This is why we use ' for the URL, this way LS continues to search for the next ".
It pretty much works like "(" and ")". The function will se a "(" and will continue until it finds the closing ")". Just with " it is not as obvious, as there is no difference between a opening " and a closing ". [/code][/code]
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Please Log in to join the conversation.
- ngolub
- Topic Author
- Offline
- Senior Member
- Posts: 48
- Thank you received: 0
I tried removing the spaces too and I just used the code you posted to be sure:
{if(TOKEN:ATTRIBUTE_1 == "Y", "<img src='https://sspgsurveyprd.ethz.ch/upload/surveys/866522/images/BEISPIEL.png' />", "")}
However, it does not work, and my version of LimeSurvey still converts ' to " upon pressing OK in code view.
This is what I see when I use ' without spaces:
I have attached my lss since you mentioned it could be helpful. The problem arises in the email template.
Please Log in to join the conversation.
- holch
- Offline
- LimeSurvey Community Team
- Posts: 11660
- Thank you received: 2742
However, the token attribute ATTRIBUTE_1 is called "token" in your token table. What does this attribute contain? Because our test is checking for "Y". Only if it says Y in the token table the image would be shown if everything elese would work fine. Of course there must be other issues, but this is something you need to look into as well.
And I just checked the invitation email template and when i correct the " vs the ' at the right place, it saved without an issue. No switching back to " from '.
Not sure what is happening on your side. But maybe it has to do with the WYSIWYG-Editor. I have it switched off, or on demand as a pop-up.
{if(TOKEN:ATTRIBUTE_1 == "Y", "<img src='/6/upload/surveys/866522/images/BEISPIEL.png' />", "")}
Try in a different browser, maybe a browser plugin is trying to interfere. From what I can see it is not Limesurvey.
{if(TOKEN:ATTRIBUTE_1 == "Y", "<img src='/6/upload/surveys/866522/images/BEISPIEL.png' />", "")}
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Please Log in to join the conversation.