I have this string in JSON format:
"message": "<?= __('I agree to the <a>Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"
What I want to do is add a link to the string of this form
"message": "<?= __('I agree to the <a href="%1">Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"
But when I do this I get the following error:
SyntaxError: Unexpected token h in JSON
How can I add the link to the tag in a correct way?
asked Apr 24, 2019 at 10:05
Cristi
5411 gold badge9 silver badges21 bronze badges
2 Answers 2
You have to escape the double quotes in the string like:
"message": "<?= __('I agree to the <a href=\"%1\">Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"
answered Apr 24, 2019 at 10:08
Jjagwe Dennis
1,87312 silver badges13 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
If you have any string, it's best to just convert it to json, the function will handle all your characters that require escaping.
In php it can look like this:
"message": <?= json_encode(__('I agree to the <a>Terms of Service</a>', $block->getUrl('terms-conditions'))) ?>
each language should have similar json encode function, just search in google for you language.
answered Apr 24, 2019 at 10:12
jcubic
67.1k58 gold badges252 silver badges466 bronze badges
Comments
lang-js
\"%1\"