Minimal example for ${process.env.BaseURL}/foo

Hi guys,

Having a bad day here:

hugo new site minimal
cd minimal
mkdir -p layouts/foo
echo "<h1>Hello World</h1>" > layouts/index.html
echo "<h1>Hello foo</h1>" > layouts/foo/index.html
hugo

How come there is no “foo”? What am I missing?

$ grep -r Hello minimal/public/
minimal/public/index.html:<h1>Hello World</h1>

Thank you in advance!

echo "<h1>Hello foo</h1>" > layouts/foo/index.html

bash: layouts/foo/index.html: No such file or directory

The echo command does not create directories.

Sorry @jmooring… I should have double checked my minimal reproducible snippet there. I just added a mkdir line.

Still the problem maintains, no /foo path!

Hugo, by defaults, creates pages for

  • Each content file
  • And some standard pages for home, sections and taxonomies (if no content file for them exists)

/foo does not match any of the above.

Thanks @bep. Enjoying your work on Hugo!

Though content doesn’t get rendered without a layout file, right!?

hugo new site ${1:-"testing"}
cd ${1:-"testing"}
mkdir content/foo
echo "# Hello from foo" > content/foo/index.md
hugo

The above doesn’t render anything and doesn’t even warn, at least in a way that tells me foo/index.md will not be shown. Tbh kindof expected hugo to assume {{ .Content }} for simplicity sake.

So the minimal way I’ve found of creating an arbitrary path is something like:

hugo new site ${1:-"testing"}
cd ${1:-"testing"}
mkdir layouts/_default
echo -e "<h1>Hello from layouts</h1>\n{{ .Content }}" > layouts/_default/single.html
mkdir content/foo
echo "# Hello from foo" > content/foo/index.md
hugo

For my https://github.com/kaihendry/shopfront project I need a special /success and /cancel page. At first I assumed I could do this simply from /layouts, but it appears not. Unless I am missing missing some other trick??

And then I have the next problem of trying to make sure /foo doesn’t appear in the sitemap not index.xml

Cheers!

Are you sure?

This is the output I get trying your setup:

hugo new site minimal
cd minimal
mkdir -p layouts/foo
echo "<h1>Hello World</h1>" > layouts/index.html
echo "<h1>Hello foo</h1>" > layouts/foo/index.html
hugo
WARN 2020/09/29 13:08:07 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/09/29 13:08:07 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
mkdir content/foo
echo "# Hello from foo" > content/foo/index.md
hugo 

WARN 2020/09/29 13:10:53 found no layout file for "HTML" for kind "page": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/09/29 13:10:53 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/09/29 13:10:53 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

The found no layout file for "HTML" for kind "page" is telling you that you need a layout file for the page kind, i.e. content/foo/index.md.

If you need to use a special layout for a special page, i.e. you want content/foo/index.md to not use _default/single.html, you need to specify a custom type/layout in your frontmatter.

---
title: foo
type: foo
---

will use layouts/foo/single.html

---
title: foo
layout: foo
---

will use layouts/page/foo.html

Docs: https://gohugo.io/templates/lookup-order/

Since the warning doesn’t tell you the culprit file missing a template, it’s pretty useless.

Anyway, without getting bogged down in this, if I want to create a /success or /cancel path with HTML on it, IIUC I need to create markdown in content/ with an accompanying layout. There is no way I can get away with a static HTML file, is there?

You can also create a file at static/success.html or wherever, assuming you don’t need page variables or template logic.

Ah static! Feels a bit strange that layouts/ couldn’t suffice.

Thank you,

Nothing strange.

Layouts (& assets) = process
Static = copy

Still doesn’t explain why a file in /layouts is enough to provide /foo path.

Seems inconsistent to me, and a bit of a gotcha.

just read this

The lookup order column makes me dizzy.

Does it explain why echo "<h1>Hello foo</h1>" > layouts/foo/index.html doesn’t work?

This, no.

But Pointyfar gave you the solution already. Did you done it ? This could explain.

You need content AND layout (outside of using /static for copying html)

That’s inconsistent with people’s first experience of using hugo, when they do something like echo "<h1>Hello World</h1>" > layouts/index.html. That works.

Minute you try paths with /layouts, it silently fails. I find this confusing. Maybe I’m the only one. :laughing:

Yes … may be.

Or may be refusing to understand how Hugo works is an other.

Again Bep already gave you the right information to understand how it works:

Hugo, by defaults, creates pages for
 * Each content file
 * And some standard pages for home, sections and taxonomies (if no content file for them exists)
 /foo does not match any of the above.

I think I get it.

At the moment it seems you think in terms of html and then you look for layouts. That is not the proper way of thinking with hugo

You should think in terms of content (md) and sections. And if the defaults layouts not suits your needs, THEN you can start customize layouts.

Well there is no default layout. Anyway, I figured it out here:

Thank you!