1

I have an embed template to which I'm passing variables from some custom channel fields. Everything works as expected until there are quotes (") inside the variable.

For example, I have the variable {article_content} inside the "section/subsection" template containing html markup with a few paragraphs and some links. I pass the variable to the embeded template using:

{embed="embeds/.article_template" emb_article_content="{article_content}"}

On the embeded template I use:

{embed:emb_article_content}

When I render the page, everything is ok until the engine reach the first quotes (") in a link, then nothing is redered. I get something like this:

<p>This paragraph is alright because doesn't contain links or quotes</p>   
<p>This paragraph contains a link <a href= 

I have tried to find ways to escape the quotes but I just can't figure out how to do it.

Any ideas to solve this issue would be greatly appreciated!

0

I managed to solve this. I used htmlspecialchars before passing the variable and in the embedded template I used htmlspecialchars_decode before using the variable. In case anyone is interested, it looks something like this:

On the template in which I embeded the template I did this:

{embed="embeds/.article_template" emb_article_content="<?php echo htmlspecialchars('{article_content}');  ?>"}

Then on the embedded template I decoded the variable like this:

<?php echo htmlspecialchars_decode('{embed:emb_article_content}'); ?>

I'm sure there are more efficient ways to do this but this works for now. I'd still like to hear any other solutions.

For those who want to use this solution and are beginners like me, don't forget to enable PHP in both templates with PHP parsing stage set to "Output".

Cheers!

EDIT:

This whole thing can be solved by just using simple quotes (') instead of double ones (") like this:

{embed='embeds/.article_template' emb_article_content='{article_content}'

This assumes that there are no simple quotes inside your variable, otherwise there will be conflicts as well. If you are sure there won't be any conflicts you can use this solution, but to be safe, I think I will stick to encoding and decoding any variable with possible conflicts.

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.