I’d like to have certain sections of content not published as pages, but use the content elsewhere.
For example, a content section:
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.
ignoreFiles = "foo$" I can have Hugo not publish the pages, but then I can’t access any of the underlying content in my templates.
Is there any workaround for this behavior?
No, but it has bene mentioned on GH recently – I think there even is PR in about this as well.
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.
Are there negative perf consequences to
readDir as well (just thinking of the current docs)?
In my quest to create as many examples as possible, I did add the following to the docs concept.
I can delete if too hackish.
Thanks guys. I’ll see if I can spec out the feature on GH soon.
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.
Okay, for the time being I will leave the example as is but add some terse copy re: perf consequences and a pointer to
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.
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.