Shortcode templates with subreferences

hi.

i want to create a single file that i can use to standardize naming conventions. i recognize that i can use shortcodes to create this, but my current understanding is that i would need a single shortcode file for each standardized name - i would end up with 50+ files.

is it possible to write a shortcode file where i would have subcodes, or the like, and i can list and maintain the names in a single file?

example of what i’m trying to do.

shortcode file: produt.html

file contents (i know that this isn’t the right syntax):

prod1=‘Orange’
prod2=‘Apple’

in my doc, i could write:

If you would like to accomplish this task easily, you should use an {{<product.prod1>}}. If that doesn’t work for your function, you could also try an {{<product.prod2>}}.

this would display as:

If you would like to accomplish this task easily, you should use an Orange. If that doesn’t work for your function, you could also try an Apple.

So, I would recommend that you pass these product types as attributes to the shortcode, e.g.:

{{<product type="apple" >}}
1 Like

how would you structure the html file then?

https://gohugo.io/templates/shortcode-templates

thanks but the documentation doesn’t make much sense to me. i find it more confusing than informative. sorry

Would you like someone to code your shortcode for you?

no. i’m fine with code, but the documentation confuses me more than it help.

what i need is an example of what the shortcode.html file might look like and the content reference. I can’t discern from the documentation how to structure the two parts.

how would i structure the above example? :
If you would like to accomplish this task easily, you should use an Orange. If that doesn’t work for your function, you could also try an Apple.

Content markdown would look like:

Html template file (product.html) would look like:

thanks.

Maybe this helps: https://discourse.gohugo.io/t/shortcode-templates-with-subreferences/37657 · GitHub

Could be more elegant but you want to understand the steps, I presume.

1 Like

thank your very much for your illustration. that makes so much more sense. i didn’t realize that i needed to create a logic block to house the options. perfect! i am in your debt.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.