[Solved] Adding lightbox subfolder path in shortcode?

Hi,

I’m still playing with Page Bundle in order to create the perfect workflow for my little needs.

I already solved the gallery issue but now I have a question regarding images subfolder in shortcodes :

{{ $img := .Page.Resources.GetMatch (.Get "img") }}
{{ $align := (.Get "align") }}
{{ .Scratch.Set "image" ($img.Resize "256x q80") }}
{{ $scaled := .Scratch.Get "image" }}  
<a href="{{ $img.RelPermalink }}">
  <img class="thumbnail {{ with $align }}{{ . }}{{ end }}" src="{{ $scaled.Permalink }}">
</a>

The shortcode is pretty simple {{< lightbox img="images/lightbox/image.jpg" align="right" >}}
Because I want to put every images used with JS lightbox in images/lightbox I don’t want to write that in my shortcode.

Any idea how I can modify my shortcode in order to directly add images/lightbox/ inside and thus only have to write the filename in my blog posts ?

Thanks a lot :slight_smile:

If I understand you correctly:

{{ $img := (.Page.Resources.ByType "image").GetMatch ( printf "images/lightbox/%s*" (.Get "img"))  }}

Totally untested …
Notice the asterisk in the matcher. You can even be less specific if the filenames are unique enough:

{{ $img := (.Page.Resources.ByType "image").GetMatch ( printf "**%s*" (.Get "img"))  }}

Thanks,

It works :+1:

I really have to learn GO a bit more, I already tried to play with printf but it seems that I missed the %s.
I don’t understand what %s represents, is it to point out the current directory we are going to be working in ?

It is a “string placeholder” … You can use %d for numbers … printf is pretty powerful