Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Conditional logo based on merged field

Hi, I have customers from "company A" and "company B" both identified with a corresponding merged field in the survey access data.
How can I display a logo of the right company in the survey header depending on the value of the merged field?
Many thanks, Thomas
asked Jan 17, 2012 by anonymous
retagged Sep 13, 2012 by Walter Williams

3 Answers

0 votes
https://sawtoothsoftware.com/forum/183/conditional-image-on-basis-of-question-num the same answer would work for you. just use the merged field as your reference question
answered Jan 17, 2012 by Bahadir Ozkurt Gold (16,980 points)
Thank you, however I still have a script error when taking this approach:
My code is (using v8 beta, "Kunde" is the merged field):

[% Begin Unverified Perl
my $a=VALUE("Kunde");
if($a eq 'Real')
return '<img src=\"\[%GraphicsPath()%\]Real.png\" alt=\"\" border=\"0\">';
return 'Kunde ist nicht REAL';
End Unverified %]

If I enter a password where "Kunde" is not "Real" it works. But it works not when "Kunde"="Real", so the error is with the returned image.
However, to check, I entered this in the footer of the same question and the image shows up.
<img src="[%GraphicsPath()%]Real.png" alt="" border="0">
hmm, I don't have v8 installed on this machine and don't have the time to install it to be honest. if you'd like to pursue this method, enter as a respondent whose "Kunde" is not "Real" and on this specific page, "view source" in browser and paste the outcoming HTML source code into http://pastebin.com/ and link here so we can try to see what's wrong.
Hope that this will help:
argh, sorry my bad. I meant when Kunde=Real :)
here it goes:
return '<img src=' . GRAPHICSPATH() . 'Real.jpg">';

replaced the code with perl function
0 votes
If you use dynamic headers/footers, make sure you enter your code into each individual question rather than under the survey settings as errors occur.

Save the logo files in the job graphics folder and use the [%GraphicsPath()%] function.

e.g. [%GraphicsPath()%]logo1.jpg
answered Jan 17, 2012 by Paul Moon Platinum (98,670 points)
0 votes
I have successfully done this in the past (both company logo in the header and helpdesk email addresses in the footer) by using lists.  Just create the parent list as usual with the logos as the members, and then create a conditional list based on your merged info.  Then just reference the conditional list in your global header.

Good luck!
answered Jan 17, 2012 by Marion Silver (5,240 points)
I thought it doesn't like the "[%" or "%]" in the <jobname>login.html file?
Hi Marion, that sounds interesting. Could you please provide an example of how to "create a conditional list based on your merged info.  Then just reference the conditional list in your global header."
Many thanks, Thomas
1.  Create a parent list.  For example, a list called LOGOS.  The members would reference the graphics folder like this: <img src="[%GraphicsPath()%]Logo 1.jpg" alt="" border="0">.  You will have as many list members as you have logos to show.

2.  Create a conditional list.  For instance, LOGOshow.  When I did this, I had a merged field in the sample called "Brand".  I made this a numeric field.  My conditional list, then, used basic SSI script - ADD(Logos,Brand).  Since the field "brand' was numeric, it populated the conditional list with the correct logo.

3.  In the global header, I added the SSI script: [%listlabel(LOGOshow,1)%]

This works just fine as long as you use the "one click" method of entry for respondents - so not through the login.html page.  Once the code picks up on the merged field, all is good.  If you DO need to allow folk to enter using the generic login page, you WILL need to do as Mr Moon has said and add the code to each and every page.  I would still choose to just put the listlabel on there though - heaps easier and less error-prone.  And if your client asks for a change, it's just one change in one place.
Thank you Marion, that is really nice!
Hi Marion, many thanks again. Just in case you're interested: I figured out another approach that is also working without the "on-click" method. I pasted this code in the header section of the survey settings:
[% Begin Unverified Perl
my $a=VALUE("Company");
$a =~ s/\s+//;
return '<img src=' . GRAPHICSPATH() . $a . '.png border=\"0\">';
End Unverified %]
"Company" is the merged in field, that is then stripped of any blanks. Then a graphic with that name is displayed as logo on all survey pages. If there is no corresponding logo, nothing is displayed.