Add built-in shortcodes in templates

Going through the docs, I found a lot of information on (built-in) shortcodes and partials. Unfortunately, I did not found information on how to use built-in shortcodes within templates.

Being more specific, I use the academic template and in one place, I want to replace the text field with a vimeo/youtube video. The content of the text field is passed by using variables e.g.:

video_id = "123456"

If I use within the template the shortcode syntax, I get an error.

{{< vimeo $video_id >}}

Any tips to circumvent this?

Hi @eddiz. Shortcodes are only used within content files.

1 Like

sorry, I might be mixing up things/concepts - still new and learning. But isn’t a shortcode in the end a reference to a partial? So I should be able to use the partial for embedding youtube/vimeo etc.?

In a nutshell, shortcodes allow you to use template logic directly in your content. If you’re editing a template, no need to use a shortcode. Whatever code is inside the shortcode, you can likely copy/paste into your template.

1 Like

but isn’t the philosophy of shortcodes and partials - write once re-use it everywhere? Basically try to avoid copy/paste operations? Why do I have to redefine something, that is already there, instead of just making a call to the built-in functionality?

Sidenote: Where are the built-in shortcodes defined?

1 Like

No, partials are reusable code for templates, shortcodes are reusable code for content. If your use case allows for reusing code between the, then you will probably figure it out. But most shortcodes and partials do not share code from a practical standpoint. I have no philosophical qualms with that. :slight_smile:


Thanks for the clarification and quick response.
For me personally, shortcodes seem to be the smallest entity of partials - but well.

1 Like

So, a shortcode can include partials (which is fairly common), but even if using shortcode templates from “regular templates” is possible, I don’t think it is practical. A shortcode will typically have a different API.

1 Like

more for curiosity - how would the syntax look like? Because simply embedding the shortcode in “regular templates” caused errors for me.

{{ template "shortcodes/foo.html . }}

Or something; but I would expect most shortcodes to fail, because they expect some particular input, which is why I said that it’s easier to do it the other way.

Or something … That said, your shortcodes most likely expect the argument it’s getting when invo