Html-webpack-plugin: How to pass template parameters

Created on 23 Jun 2015  路  9Comments  路  Source: jantimon/html-webpack-plugin

side story: Just starting to integrating webpack to replace requirejs.

How to pass template parameters to custom template?

Most helpful comment

What's the case for templateParameters then?

All 9 comments

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 :)

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

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

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?

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

@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.

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

What's the case for templateParameters then?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hackteck picture hackteck  路  3Comments

ghaiklor picture ghaiklor  路  3Comments

lonelydatum picture lonelydatum  路  3Comments

yyx990803 picture yyx990803  路  4Comments

GerkinDev picture GerkinDev  路  3Comments