I hope you’re doing well. I’m working on a Markdown file and I’m trying to figure out how to use the output of one shortcode as the input for another. Specifically, I want to take the output from a shortcode test1 and use it as the input for another shortcode test2. I’m not sure how to implement this within a Markdown file.
Example of What I’m Trying to Achieve
Let’s say I have the following shortcodes:
md
{{< test1 param1="value1" param2="value2" >}}
This would output something like:
md
347
Now, I want to use output-from-test1 as the input for test2:
md
{{< test2 input="347" params="someparams">}}
So, my goal is to combine these two shortcodes like this:
Thank you a lot,
While it looks complicated and voluminous, I would like to find a more universal solution, maybe this is it, I will study it. Please tell me, if you have any more information for me
you will need to read about Custom Shortcodes, templating language, Context, Scratch, …
So I’m unsure what to tell you cause I don’t know how deep you are in.
here’s a basic starter using shortcodes with positional parameters to study while browsing the docs.
Try it out, read the docs play around.
Hope that’s what you have been looking for.
index.md
# store the result in _variable_ var1
{{< add var1 2 4 >}}
# store the result in _variable_ var2
{{< add var2 3 2 >}}
# print formatted result of multiplying values _var1_ and _var2_
{{< mul "var1" "var2" "Result: %d" >}}
shortcodes for mul and add
the mul and add within the shortcodes are the standard functions from Math functions | Hugo