Shortcode Question

I am trying to create a shortcode that outputs the value of the .Site.BaseUrl variable. My goal was to confirm templates worked with a simple test.

  1. I created a template called layotus/shortcodes/footest.html
  2. I riffed on the simple example from the documentation
    {{ .Get “title” }}
  3. I called the template from Markdown.
    {{% footest %}}

In the generated page, all I get is an empty <p></p>. So something is happening but there is no output. What am I doing wrong?

BTW, it appears that a template must have a .html extension which isn’t mentioned really in the docs. I’ll fix the docs once I get my own shortcode working.

Your shortcode isn’t really writing anything, as I see it.

  {{% footest title="some title" %}}

Should be more productive.

Shouldn’t this.Get "title" output the title of the current document? That is pretty much what the docs say — I can access a parameter value by name.

.Get reads parameters that are passed to the shortcode itself.

IIRC, with

{{% shortcode foo="bar" user="bob" %}}
{{ .Get "foo" }}   =>  "bar"
{{ .Get "user" }}  =>  "bob"

If you instead use positional parameters, then

{{% shortcode "bar" "bob" %}}
{{ .Get 0 }}  =>  "bar"
{{ .Get 1 }}  =>  "bob"

To get the title of the page, something like

{{ .Page.Title }}

should work.

Thank you @lotrfan that sorted me out. Also, your examples were super clear…I’ll move those to the docs too.

And looking at the code it looks like it looks like the variables have to be .Page also. This wasn’t immediately obvious to me. Anyway, I’ll take a stab at a page rewrite to clarify this stuff.