Gulp, html templates and fragment loading

I want to import html fragments in different places in the generated html file when I run it through the gulp task.

Below is my gulp task:

gulp.task('build_html', function () {
    gulp.src('resources/index.html')
        .pipe(template({ident: '1'}))
        .pipe(gulp.dest('frontend'));
});

Inside the index.html file there is a lot of html that I would like to load from fragments, for example, the bootstrap popup menu

 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>

which I would like to download having something like

<% load("dropdown"); %>

And then it looks for the dropdown file in the relative path ...

In any case, I suppose this should be done using the mixin function http://lodash.com/docs#mixin but given that I am using gulp I need a file downloader, etc.

Has anyone already done this or has an example that they can point me to?

+4

Source: https://habr.com/ru/post/1540948/


All Articles