Using shortcode code1.html within an other shortcode code2.html

The issue I have seems to be the same as the one raised in this other question, but I did not really manage to follow the answers and understand if this has been really answered.

Let say I have a shortcode code2.html and I want to use this within the code of an other shortcode code1.html. Note that here I consider very simple shortcodes: they are called without arguments and do not require closing shortcodes.

I want to write in my file code1.html

some code ...
{{< code2 >}}
... some code

This returns an error unexpected "<" in command. I have read the documentation to create your own shortcode but I could not find a way to solve this problem. Is it possible to do something like this (in a simple way), or is it out the scope of what Hugo does?

I would recommend going about this a different way. Here are two ideas:

(1) Pass the 2nd shortcode as the .Inner of the 1st shortcode. For example:

{{< shortcode-1 >}}
{{< shortcode-2 >}}
{{< /shortcode-1 >}}

(2) Put the 2nd shortcode logic into a partial, then call that partial from your 1st shortcode. See an example of that here.

Thank you very much @zwbetz for your reactivity.

I have troubles to understand how solution (1) works exactly. This .Inner function still look a bit strange to me. Sorry!

I do understand how solution (2) works. I also see that I might have oversimplified a bit too much my problem. So let me add the additional constraint that code2 is actually called with one argument. I don’t think that solution (1) can handle that because partial do not take argument. Tell me if I am wrong, and please let me know if you think that solution (1) could handle this well.

So now ´code2´ is called with some argument(s), and ´code1´ should look like:

some code ...
{{< code2 arg1 >}}
... some code ...
{{< code2 arg2 >}}
... some code ...
{{< code2 arg3 >}}
... some code ...
...
... some code ...
{{< code2 arg10 >}}
... some code

I could help you more if I knew what these shortcodes should be doing, because maybe there is a better way. Do you have some concrete examples?

Thank you for your support.

I have in my data folder several YAML files, say lecturer1.yaml, lecturer2.yaml, …

On a content page program.md where I present the program of a workshop, I am calling a shortcode {{< timeTable >}}. This is my code1 from the messages above.
In timeTable.html I have some html code to define a table in which I have different information, and in particular a series of cells which should display in a uniform way information extracted from the files lecturerX.yaml, such as name of lecturer, university of lecturer, title of the talk of the lecturer,…
My idea was to create a shortcode timeTableEntry.html (code2from the above messages). This shortcode should have as argument the name of the lecturer and display the corresponding information.

Thanks for the info. So I think you could accomplish this more cleanly with a single shortcode. You could pass each lecturer as an arg to timeTable, then in the shortcode definition, range through each arg and build your HTML table.

A quick example. Let’s say you passed 3 lecturers to your shortcode:

{{< timeTable "lecturer1" "lecturer2" "lecturer3" >}} 

Then in your shortcode definition:

<!-- start of your HTML table -->
{{ range .Params }}
  {{ . }} <!-- do something with each lecturer passed in -->
{{ end }}
<!-- end of your HTML table -->

Thanks.
I though about it this at first. I might end doing something like this, but it is not yet entirely clear to me how. The problem with ranging through the participants given as arguments is to deal with all the non-lecture-info such as coffee break, lunch break, poster session, social dinner… they should also appear in the time table.

Well. This might have not answered as I wished. In particular, I understand that we cannot easily call a shortcode within a shortcode (as described above) in an elementary way. But this discussion has brought some new perspectives and way to tackle my problem. Thanks again.

Welcome. Wishing you good luck. And although it doesn’t answer your question, this may be useful to you when building your HTML table.

Thanks for the link. Indeed it gives me some ideas of new things to try. :slight_smile: