Have an idea?

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

Show image based on variable


Im trying to show a specific image based on a variable in my survey:

Begin Unverified Perl
if(GETVALUE("vMDLayout") > 1)
return '<img src="[%GraphicsPath()%]MDLayout1.jpg" alt="" border="0">';
return '<img src="[%GraphicsPath()%]MDLayout2.jpg" alt="" border="0">';
End Unverified

But I am getting a PERL error, any ideas how I can achieve this?  Thanks
asked Jul 3, 2019 by Michael

1 Answer

+1 vote
You are seeing an error because you are nesting Sawtooth Script like "[% [% %] %];" this is not allowed.  Instead, you need to either restructure the code to remove the nesting, or replace the inner Sawtooth Script with their unverified Perl equivalents and string concatenation.

Option 1 example:

<img src="[% GraphicsPath() %]MDLayout[% Begin Unverified Perl
if (...) {
    return 1;
else {
    return 2;
End Unverified %].jpg"/>

Option 2 example:

return '<img src="' . GRAPHICSPATH() . 'MDLayout1.jpg"/>';
answered Jul 3, 2019 by Zachary Platinum Sawtooth Software, Inc. (205,575 points)