L
L
liltrill2019-11-02 19:41:51
webpack
liltrill, 2019-11-02 19:41:51

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

2 answer(s)
Z
zorinleonid, 2019-11-02
@zorinleonid

count - is it 5?

let count = 5;
document.cookie = "count=5";

<div class="question-wrap__title"><?php echo $_COOKIE['count'];?></div>

M
Mariomens00, 2020-12-08
@Mariomens00

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 question

Ask a Question

731 491 924 answers to any question