What are the pros/cons of using a "baseOf" template or the standard template?

Just wondering what the benefits are to doing a site with templates built upon the baseof system and sites build on the standard (non-baseof) system.

I’m curious as to what you mean by “standard” here, since I don’t know if we’ve ever defined a standard way for making websites with Hugo.

That said, I think what you’re asking about is the difference between using base templates/blocks and just using partials.

My personal preference is to use both, but generally speaking, I think base/block templates keep your code DRYer. Generally speaking, websites have a “chrome” (i.e., site header and site footer), so there is no reason you wouldn’t want to keep this in at least a layouts/_default/baseof.html template, IMHO.

Using blocks is great for things like, maybe, an addscripts, which defaults to blank but can be redefined as a block in subsequent templates. The block can also include multiple sort of “default” partials it uses unless redefined within a template.

Generally, I think this is going to depend on user preference and site complexity. Generally, I only find I need a single baseof.html and create as many partials as possible for easier reuse (especially with functions like dict) and organize them into semantically named directories that treat them like components.

HTH.

To me the most important part is getting all templates as well formed HTML (with Go template tags inserted here and there), which is kind of impossible to do with just partials (without massive duplication). No HTML formatter will do a good job with the latter.

2 Likes

Per @bep’s suggestion, I should have mentioned that the partials-as-components has the “well-formed” idea baked into it. This is something we talked about on GitHub. I was reminded as soon as Bjørn Erik made the previous comment:

https://github.com/gohugoio/hugo/issues/3576#issuecomment-307637628

I didn’t know how to name the non-block method, so I guess just using partials is what it would be. One theme i’m working with doesn’t use baseof.html. So each type of page i want has it’s own fully populated file (with partials of course)… like the single.html, list.html, index.html. Inside they reference the footer.html partial and header and pagination and all that stuff.

Others i’ve seen use the baseof.html method, and I think I understand the routing logic of them. but since there is a mix of techniques in all the Hugo themes, I didn’t know which was better or more recommended.

@bep I’m not sure what you mean about well-formed HTML and an HTML formatter. Are you saying with just using partials, there is a lot more duplicated boilerplate that could be handled better with a baseof style?

I’d venture to guess that the themes that don’t use baseof either predate the method or the theme author was uncomfortable with it, or something like that. In my view there is no reason not to use baseof. Your templates will be cleaner with less duplication and more consistency.

1 Like

This is good to know. What I needed to hear.

1 Like

But do you know why they are called “baseof.*”?

because that file is the base of the template that was called for render… which if you look in the called template (single.html or whatever) you see the {{ main }} (syntax is not checked on that) call out saying that what follows is part of the baseof.html template?

No, the real answer is a little more exotic, and Swedish.

“All that she wants is another baby…”

2 Likes

Wow. That opened up my eyes I saw the sign.

And just to give some context: Ace templates were the first to get this base template support, so we got “baseof.ace” files… And I just continued the same name standard for Go templates => baseof.html.

3 Likes

I feel like this is going to be in an episode of Unknown History or something. Once Hugo has dominated the web.