question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for partial html files

See original GitHub issue

Could you provide an example of how to use partials in the html files?

Describe the solution you’d like It would be great if the boilerplate supported partials (includes) and used them in the index.html file

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
mathieuhasumcommented, Oct 24, 2018

Hey, thanks for the great boilerplate! I think adding a template engine (like mustache-loader or handlebars-loader for Webpack) could be great! On one hand I appreciate the simplicity of using pure HMTL, but in practice code splitting quickly becomes needed (for a shared navigation menu for example).

Concretely, that means we would write .hbs files (using Handlebars) instead of .html files, gaining the benefits of using variables or includes.

<div class="entry">
  <h1>{{title}}</h1>
  <div class="body">
    {{body}}
  </div>
</div>

Everything will be compiled into static HTML with webpack, no performance issue here.

I could look into that and send a PR, But it’s up to you @erickzhao if you’re willing to drop pure HTML 😃

Edit : And if I’m not wrong, this would be completely optional. Up to developers to create .html or .hbs files. So you get the best of both worlds 😃

1reaction
bgreatercommented, Oct 4, 2018

@erickzhao so far here is what I’ve done to get something working. Now it doesn’t support variables which I think would be the next step (maybe using mustache-loader) but having the ability to split up repetitive code is a step in the right direction…

in webpack.config.common.js

...
{
        test: /\.html$/,
        loader: 'html-loader',
        options: {
          interpolate: true
        }
      },
...

in index.html

...
${require('./_partials/test.html')}
...

As I understand it the partial is relative to the file calling it and not the root. But this has allowed me to bring in common html snippets for multiple pages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Partial render in HTML/JavaScript - Stack Overflow
I have some HTML files, and each one of them I want to partially render in another HTML file, for example header.html and...
Read more >
The Simplest Ways to Handle HTML Includes | CSS-Tricks
The Simplest Ways to Handle HTML Includes · Use PHP · Use Gulp · Use Grunt · Use Handlebars · Use Pug ·...
Read more >
How to Modularize HTML Using Template Engines and Gulp
Template engines are tools that help you break HTML code into smaller pieces that you can reuse across multiple HTML files.
Read more >
How can you use a partial HTML file inside a template as a ...
As I tried to build this sort of “function”, I have create a partial file named phone.html that contains this very basic code:...
Read more >
Partial views in ASP.NET Core | Microsoft Learn
A partial view is a Razor markup file ( .cshtml ) without an @page directive that renders HTML output within another markup file's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found