Skip to content

How can I provide parameters for webpack html-loader interpolation? #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
547377507 opened this issue Apr 12, 2017 · 4 comments
Closed
Assignees

Comments

@547377507
Copy link

require("html?interpolate=require!./file.ftl");

<#list list as list>
${list.name}
</#list>

${require('./components/gallery.html')}

Where does "list" come from? How can I provide parameters to the interpolation scope?

I would like to do something like template-string-loader does:

var template = require("html?interpolate!./file.html")({data: '123'});
and then in file.html

${scope.data}
But it doesn't work. I have try to mix the template-string-loader with the html-loader but it doesn't works. I could only use the template-string-loader but then the images in the HTML are not transformed by webpack.

Any ideas? Thank you

@michael-ciniawsky michael-ciniawsky self-assigned this Apr 12, 2017
@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Apr 12, 2017

@547377507 Currently not possible sry, I'm working on #120 for the next major of this loader, the README example is misleading here, it only shows that if ?interpolate=require other ${} stay unaffected in case you deal with them otherwise somehow 😛 . I took a quick look at the template-string-loader source and it does exactly, what I want to add to html-loader in the near future. Having it in html-loaderis the better option, since you can import a template function into your components js|jsx|ts|tsx directly and call it when needed, but for now you can send PR to template-string-loader if you want :)

template-string-loader/index.js

import { getOptions } from 'loaderUtils'

module.exports = function (html) {
   const options = getOptions(this) || {}
   // html-loader etc following
   if (this.loaderIndex > 0) {
      const template = ($) => `${html}`
      return template(options.locals)        
   }
   // direct export to webpack as a module
   return 'module.exports = function ($) { return `${html}`};'
}

@547377507
Copy link
Author

Thank you

@machsix
Copy link

machsix commented Dec 9, 2019

Is there any update on this? I found https://github.com/deepsweet/mustache-loader, which seems to achieve the goal. But I would like to stick with ES6 syntax

@denis-migdal
Copy link

Is there any update on this? I found https://github.com/deepsweet/mustache-loader, which seems to achieve the goal. But I would like to stick with ES6 syntax

Hi, I just created a package that might do what you are asking:
https://github.com/denis-migdal/prehtml-loader

I will create a new issue in this repository to talk about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants