Welcome to the LimeSurvey Community Forum

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

Inserting an image using TOKEN:ATTRIBUTE

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 3 weeks ago - 1 month 3 weeks ago #257812 by ngolub
Please help us help you and fill where relevant:
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.
Last edit: 1 month 3 weeks ago by ngolub.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago - 1 month 3 weeks ago #257864 by holch
Replied by holch on topic Inserting an image using TOKEN:ATTRIBUTE
Of course you can do this via a custom token attribute.

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.

Last edit: 1 month 3 weeks ago by holch.
The following user(s) said Thank You: ngolub

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 3 weeks ago #257871 by ngolub
Replied by ngolub on topic Inserting an image using TOKEN:ATTRIBUTE
Thank you for your reply! I am glad to hear that this can be done!

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
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #257877 by holch
Replied by holch on topic Inserting an image using TOKEN:ATTRIBUTE
Oh, I must have overlooked this part:

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):
Code:
{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.

The following user(s) said Thank You: DenisChenu, ngolub

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 3 weeks ago #257882 by ngolub
Replied by ngolub on topic Inserting an image using TOKEN:ATTRIBUTE
Thanks!

I'll test it and let you know how it works here.

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 3 weeks ago - 1 month 3 weeks ago #258117 by ngolub
Replied by ngolub on topic Inserting an image using TOKEN:ATTRIBUTE
Hi

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?
Last edit: 1 month 3 weeks ago by ngolub. Reason: add information

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258118 by holch
Replied by holch on topic Inserting an image using TOKEN:ATTRIBUTE
You did not look at my example in the necessary depth.
Code:
{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:
Code:
{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.

The following user(s) said Thank You: ngolub

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258119 by holch
Replied by holch on topic Inserting an image using TOKEN:ATTRIBUTE
Also, you seem to have posted this in the WYSIWYG editor. You need to do this in the code view, or it will only be just text.

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.

The following user(s) said Thank You: ngolub

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 3 weeks ago #258122 by ngolub
Replied by ngolub on topic Inserting an image using TOKEN:ATTRIBUTE
Thank you so much for the quick reply!

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:
Code:
{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
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago - 1 month 3 weeks ago #258123 by holch
Replied by holch on topic Inserting an image using TOKEN:ATTRIBUTE
Code:
{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:
Code:
{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.

Last edit: 1 month 3 weeks ago by holch.
The following user(s) said Thank You: ngolub

Please Log in to join the conversation.

  • ngolub
  • ngolub's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 3 weeks ago #258125 by ngolub
Replied by ngolub on topic Inserting an image using TOKEN:ATTRIBUTE
Thank you for the reply.

I tried removing the spaces too and I just used the code you posted to be sure:
Code:
{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:

 

File Attachment:

File Name: HEM_Survey_V03.lss
File Size:966 KB


I have attached my lss since you mentioned it could be helpful. The problem arises in the email template.

 

File Attachment:

File Name: HEM_Survey_V03.lss
File Size:966 KB

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258126 by holch
Replied by holch on topic Inserting an image using TOKEN:ATTRIBUTE
I am checking, but as you did not deliver the survey with a token table, I can't really test it out of the box.

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.
Code:
{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.
Code:
{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.

The following user(s) said Thank You: ngolub

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose