Created
August 12, 2024 02:25
-
-
Save TuVanDev/89687d65dfe1c7b2f3b06cf5b5f40382 to your computer and use it in GitHub Desktop.
render-inline-JavaScript-with-secureRenderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer | |
*/ | |
?> | |
<div id="vue-test"> | |
<h1>{{ message }}</h1> | |
</div> | |
<?php $scriptString = <<<script | |
/** | |
* Define the `require` statement inline of your PHTML template. RequireJS will automatically pull in | |
* the required dependencies, and fire off your callback after they have resolved. | |
*/ | |
require(['vue'], function(Vue) { | |
'use strict' | |
new Vue({ | |
el: '#vue-test', | |
data: { | |
message: 'This is a test' | |
} | |
}); | |
}); | |
script; | |
?> | |
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment