I’m trying to implement something in Hugo which is possible using DITA.
Let’s say I have a user manual. The content in it can be applied to a number of different products.
I want to have the text change based on the conditional product name.
So if content is for product “foo” display the text with the product name “foo”, for the product “bar” display the same text with the product name “bar”.
What is the best way to do this with Hugo?
Edit: to clarify, I want to be able to write the content in one place, then change the product name in the content depending on the model selected.
So the intro page for product one would say “Hello, welcome to the PRODUCT ONE page” and the intro page for product two would say “Hello, welcome to the PRODUCT TWO page”.
The main issue is that the content is the exact same, but just with different model numbers.
I think this should mean using templates for these pages, and empty markdown files on the content side, then apply the templates based on the markdown file.
So a markdown file for intro page would apply the template intro page with it’s variables for model numbers, and would include front matter stating that model number.
However, the way templates seem to work in hugo, I can only apply one template (single) to all pages?
I’d create a folder in content to hold your manual content and each markdown file be a piece of content for each product. Use front matter in each piece of content to associate it with products maybe using a list so it can apply to multiple products.
Sure the list of related products which you put in the manual content markdown files should match at least the file name or something in the product files front matter so you can range over it using where
I think I might be missing this, so apologies if it’s flying over my head. Did you mean including the generic markdown files within a product markdown file. How does it pick up the product name then?
If you have a page per product, you could simply either have your single.html template grab product information from your frontmatter, and put that in some fixed area of the page, or, if you need the location to be variable within your markdown, use a shortcode that does a similar thing. You could put the datapoints in a data file and pinpoint them, or, you could put the datapoints in frontmatter (assuming one markdown file per product), and pull from there.
Well, for each product there’s a bunch of pages (more than listed in example below)
so for example:
Product one intro
Product one getting started
Product one connecting to network
Product one features
Product two intro
Product two getting started
Product two connecting to network
Product two features
So I guess, what I want is a bunch of templates for each type of page, or a single template that includes a bunch of templates that change based on the page type. Then they would also include the product model in the templated content.
You don’t need to include the entire PATH to your partial. You only need to call it like so {{ partial "productintropage.html" . }} And Hugo will find it.
Ah, sorry someone (IRL) corrected me earlier today when I called them go templates :o So the approach I’ve outlined above should work? Or was your reply just specific to the partial?
OK, so this didn’t work but I’ve rethought the approach. I’d like to have all content in MD files that can be accessed for review by anyone, so doesn’t make sense to have it in templates.
I’m now stuck with an issue on the new approach I’m using:
I’ve made my own shortcode that accesses a front matter variable for productName.
In the docdock theme there’s an excerpt/excerpt-include which includes content from one markdown file in another.
I’ve created a markdown file with the text This is the {{% frontmattervar %}} user guide, wrapped in {{% excerpt %}} tags
The problem with this is that the content included is included as raw markdown, so the variable doesn’t work when it’s in the reuse file. It does work if it’s directly in the content.
First of all the DockDock theme is pretty complex and I have no experience with it. You may have better luck asking the theme’s author.
With that said when one uses {{% shortcode %}} the % tells Hugo to interpret it as Markdown.
Instead when one uses {{< shortcode >}} the angled brackets tell Hugo to interpret the shortcode as HTML.