Skip to content

Instantly share code, notes, and snippets.

@MkLHX
Last active July 14, 2020 20:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MkLHX/d4d38f4fd1fe702fdb9b2a0077ca9c81 to your computer and use it in GitHub Desktop.
Save MkLHX/d4d38f4fd1fe702fdb9b2a0077ca9c81 to your computer and use it in GitHub Desktop.
passe twig variables to javascript function Symfony 4.3.2
<!DOCTYPE html>
<html>
<head></head>
<body>
<!-- //... -->
{% set cookieData = {
msg: 'this website using cookie and by continuing navigation you accept blablablabla....etc',
btn1: 'More',
btn2: 'Accept',
path: '/privacy-policy'
}
%}
<div id="#cookieData" style="display:none;" data-cookie-data="{{ cookieData|json_encode }}">
{% block javascripts %}
{{ encore_entry_script_tags('cookie') }}
{% endblock %}
<!-- //... -->
</body>
</html>
let Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.autoProvidejQuery()
.addEntry('cookie', './assets/js/cookie.js')
.enableSingleRuntimeChunk()
.splitEntryChunks()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
.enableSassLoader()
;
module.exports = Encore.getWebpackConfig();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment