I’d like to have certain sections of content not published as pages, but use the content elsewhere.
For example, a content section:
content
/foo
bar.md
I don’t want “bar” published as a page, but I’d like to be able to use whatever is in bar’s content and front matter elsewhere in my content. I realize data files are structured for this behavior, but it’s often easier for content creators to create pages than items in a data file.
Using ignoreFiles = "foo$" I can have Hugo not publish the pages, but then I can’t access any of the underlying content in my templates.
Not exactly what you’re looking for, I know @budparr, but there is the readFile hack I used with the docs concept before you were able to (considerably) improve the code. Of course, this still means either creating blank templates or even creating files with a hackish FM field like render: false (just spitballing) and a single template that only renders content according to that field…
@rdwatters as you said, it is a hack – and we really should not spread that idea around. It will soon bite us in the ass in form of “why is my site so slow?” topics.
And this, of course, means we should not use it for the Hugo docs, either.
Neither readDIr nor readFile is cached in any way, so if you read the same file 1000 times … But if you put it behind a partialCached … we have no similar in shortcodes. It is hard to get right, which I say that it should be used sparingly.
Looking at your readFile shortcode and its usage in the docs, that looks fine – the content is rendered once, so the files are only read once per shortcode, and it is mostly different files every time.
If layouts/foo/single.html and layouts/section/foo.html are zero-length, no files will be published for section foo, but the content can still be retrieved through taxonomies, etc. This was briefly broken in 0.20-0.20.2, but was fixed in 0.20.3.