JSON with PHP tags

Answered

Hi all!

 

I've created a custom language injection in Editor for validate tag 

<script type="text/x-magento-init">

as JSON. The problem is that in this JSON I am using a PHP tags like "<?= metodToReturnJSON(); ?>". In Editor I have error that value is missing and after make auto-formating, those tags are removed from JSON.

There are any possiblity to add ignore tags? Whitelist or etc? I'd like to do RegExp to don't throw error when value is as <?=  ?>

Full example:

<script type="text/x-magento-init">
{
"*": {
"test": {
"anyValue": <?= $block->metodToReturnJSON(); ?>
}
}
}
</script>

After auto-formating

<script type="text/x-magento-init">
{
"*": {
"test": {
"anyValue":
}
}
}
</script>

What intresting as default  "text/x-magento-init" is renderer as "plain text" and after make auto-formating the breakline is added before </script> tag. Each next auto-formating is new line. Additionally, the format of JSON doesn't work for plain text. 

Can anyone give me tip what should I do to use auto-formating and those custom Magento JSON tags? 

2 comments

Hi there,

https://youtrack.jetbrains.com/issue/WI-26863 perhaps -- the most relevant that I could find in PhpStorm section.

The difference is: because it's treated as Plain Text here .. it does not remove any code for me. But if I manually inject JSON ... it will remove PHP block unless I surround that part with "".

Also, the line is added before closing </script> tag when content is not treated as JSON.

0

Thx for feedback. Yes -> it's the same case, but still without answer. Over 2 years...

0

Please sign in to leave a comment.