I have an iframe in my lightning component. The value of the src attribute of the iframe is half static and half dynamic e.g.:

<iframe src="/apex/customPage?id= \'' + {!v.linkId} + '\' " width="100%"></iframe>

But the error I am getting is this:

Cannot mix expression and literal string in attribute value, try rewriting like {!'foo' + v.bar}: Source

it should be in this way

<iframe src="{! '/apex/customPage?id=' + v.linkId}" width="100%"/>

the whole attribute value has to be within an expression {! ...}

|improve this answer|||||

As per the error message, {!'foo' + v.bar} for your expression would be something like this -

"{!'/apex/customPage?id=' + v.linkId}"

Also I would suggest you to refrain from using hard coded page names. Use the $Page global variable instead.

|improve this answer|||||

You can just do what the error message is telling you to do:

/apex/customPage?id= \'' + {!v.linkId} + '\'


{!'/apex/customPage?id=' + v.linkId}

So the literal becomes part of the expression itself whereas before you had a literal and an expressing in the same attribute, which it doesn't like.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.