Giter Club home page Giter Club logo

Comments (9)

mqklin avatar mqklin commented on May 9, 2024 9

What's the case for templateParameters then?

from html-webpack-plugin.

koko236 avatar koko236 commented on May 9, 2024 7

I was looking for the same thing. So it seems like to access plugin options from the template I need to reference them as htmlWebpackPlugin.options. That's quite verbose. Is there any way to define a 'variables' object in plugin options that could serve as 'root' for the template variables?


Eg. say I'm using Mustache. Using JS I'd render like this:

Mustache.render(template, {title: 'Hello', lang: 'en'}, {partial1: 'partial'});

Then I can simply use the variables like:

<h1>{{ title }}</h1> <img src="speechbubble_{{lang}}.png"/>

and so on. Is something similar possible with html-webpack-plugin?

from html-webpack-plugin.

jantimon avatar jantimon commented on May 9, 2024 5

It will pass all variables to the templates so you can define your own. E.g. longTitle

from html-webpack-plugin.

jantimon avatar jantimon commented on May 9, 2024 4

nope because of legacy reasons - but I really like the idea

from html-webpack-plugin.

jantimon avatar jantimon commented on May 9, 2024 2

The example on write your own templates shows how to pass the title parameter to a custom template.

Please let me know if this what you were looking for :)

from html-webpack-plugin.

StalkAlex avatar StalkAlex commented on May 9, 2024 1

it works with

  new HtmlWebpackPlugin({
    template: '../html/index-template.html',
    env: {
      Prod: !prodFlag,
    },
  }),

and read then as htmlWebpackPlugin.options.env.Prod
But according to documentation it suppose to work with

 new HtmlWebpackPlugin({
    template: '../html/index-template.html',
    prod: true
  }),

and htmlWebpackPlugin.options.prod

from html-webpack-plugin.

maks-rafalko avatar maks-rafalko commented on May 9, 2024

@jantimon What if I need to pass custom variable (not from this list of allowed variables https://github.com/ampedandwired/html-webpack-plugin#configuration)?

from html-webpack-plugin.

StalkAlex avatar StalkAlex commented on May 9, 2024

@jantimon it's not working anymore or I'm doing something wrong, cause it's injecting custom variable only if I set inject: false, but it's not what I want because in this case it's not injecting my bundles.

from html-webpack-plugin.

lock avatar lock commented on May 9, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from html-webpack-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.