Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcodes no longer work in Template files #7

Closed
beatricebock opened this issue May 25, 2017 · 3 comments
Closed

Shortcodes no longer work in Template files #7

beatricebock opened this issue May 25, 2017 · 3 comments
Labels

Comments

@beatricebock
Copy link

According to Hugo, shortcodes don't work in template files. Is there a workaround?

@liwenyip
Copy link
Owner

HEG doesn't normally need you to use a shortcode in a template file.

What are you trying to do?

In general, if you want to call a shortcode from a template, copy and paste the contents of the shortcode into your template.

@JorisEekhout
Copy link

I had the same question. I want to call the gallery shortcode from a single.html layout file. The directory argument should come from the front matter. Something like this:
{{< gallery dir="/images/{{ .Params.dir }}" />}}

But like beatrice said, shortcodes do not work in template files. Any ideas?

@liwenyip
Copy link
Owner

liwenyip commented Jan 6, 2018

You'll need to copy gallery.html into your template file, or into partial template which you call from your main template.

You'll have to hard-code all the variables normally passed to the shortcode (i.e. every instance of .Get).

e.g. Change

<div class="gallery caption-position-{{ with .Get "caption-position" | default "bottom" }}{{.}}{{end}} caption-effect-{{ with .Get "caption-effect" | default "slide" }}{{.}}{{end}} hover-effect-{{ with .Get "hover-effect" | default "zoom" }}{{.}}{{end}} {{ if ne (.Get "hover-transition") "none" }}hover-transition{{end}}" itemscope itemtype="http://schema.org/ImageGallery">

to

<div class="gallery caption-position-bottom caption-effect-slide hover-effect-zoom hover-transition" itemscope itemtype="http://schema.org/ImageGallery">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants