Answer the question
In order to leave comments, you need to log in
HTML Loader how to pass variable to html file?
Here's what's there:
'use strict';
const path = require('path');
module.exports = {
mode: 'development',
devtool: 'source-map',
entry: { main: './src/es6/index.js' },
output: {
path: path.resolve(__dirname, 'js'),
filename: 'main.js',
library: "qzilla"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(html)$/,
exclude: /node_modules/,
use: {
loader: 'html-loader',
options: {
attrs: [':data-src'],
minimize: false,
conservativeCollapse: false,
interpolate: true
}
}
}
]
},
};
let count = 5;
let question = require('./template/question/question-wrap.html');
positionInner.insertAdjacentHTML('beforeend', question);
<div class="question-wrap__title">Как сюда передать переменную count?</div>
Answer the question
In order to leave comments, you need to log in
count - is it 5?
let count = 5;
document.cookie = "count=5";
<div class="question-wrap__title"><?php echo $_COOKIE['count'];?></div>
in the template
in the file where the template is inserted
<%=tittle %>
<%= _.template(require('путь к шаблону')) ({ tittle: "Переменная"}) %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question