Image List URL Problem

Located in a CONTENT explore/beaches
{{< carousel count = “8” located = “explore/beaches” >}}

images are named image1.jpg image2…

in LAYOUTS/shortcodes/carousel.html

This works perfectly
{{ range $i, seq .Params.count }}

{{ end }}
Crashes
{{ range $i, seq .Params.count }}

{{ end }}

so does
so does

AND / OR can the URL also be created by the page location …

much thanks
go is so skinny to the new bee

opps the HTML was left out

img src=“explore\beaches\images{{ $i }}.jpg WORKS
img src=”{{ .Params.located . }}\images{{ $i }}.jpg CRASHES
img src="{{ .Params.located }}\images{{ $i }}.jpg CRASHES

What does “crashes” mean in this context? I suspect that you mean that Hugo prints an error message and fails to (completely) render. If so, could you share the error message?

I suspect it might be due to the .Params.located front matter not defined for all content or not accessible in the current context. If that’s the case, you can use the isset function (see here) to first check whether that variable is there before trying to access it.

I think you need the following syntax.

{{range $index, $element := array}}
   {{ $index }}
   {{ $element }}
{{ end }}

As you can see, you have

{{ range $index, := some_function array }}

and that is wrong syntax.

You need probably:

{{ range $index, $element := some_function array }}

For example:

{{ range $index, $element := seq .Params.count }}
          you code here
{{ end }}

Thanks for your quick reply List passing a counter and a short url
like so… {{< ctest counter = “8” located = “explore\beaches” >}}

counter: {{ .Params.counter }}
located: {{ .Params.located }}
{{ range $index, $num := (seq .Params.counter) }}
img src=“explore\beaches\images{{ $num }}.jpg”
{{ end }}
WORKS BUT NO SHORT URL

WITH THIS

{{ range $index, $num := (seq .Params.counter) }}
img src="{{ .Params.located }}\images{{ $num }}.jpg"
{{ end }}

ADD THAT AND NO HTNML not produced
Except
ERROR 2017/03/23 04:08:54 error processing shortcode shortcodes/ctest.html
ERR: template: shortcodes/ctest.html:7:28: executing “shortcodes/ctest.html” at <.Params.located>: can’t evaluate field Params in type int

I don’t know what that means. What short url? What are you trying to do?

Perhaps try $.Params.located

{{ range $index, $num := (seq .Params.counter) }}
img src="{{ $.Params.located }}\images{{ $num }}.jpg"
{{ end }}

Like this … bulk resize some photos for a blog post called explore beaches
Bulk rename them in in Windows with F2 calling them all images
Use theBulkrname progarm to strip all the brackets and to change to lower case extension
Put images the static directory same name as blog post
In blog page if 8 photos I run a carousel this way… will give the code later
{{< ctest counter = “8” located = “explore” sublocated = “beaches” >}}
I also have another short code to add some txt with images for the blog

This is a very fast way to produce conetent from shorciode ctest.html
img src="explore\beaches\images{{ $num }}.jpg WORKS
So I pas the count of files and the file names are auto generated for the carousel
img src="explore\beaches\images1.jpg"
img src=“explore\beaches\images2.jpg” etc

I can get this to work if i specify the directory

BUT
Img src="{{ .Params.located }}{{ .Params.sublocated }}\images{{ $num }}.jpg"
but this fails with the error
at <.Params.located>: can’t evaluate field Params in type int

I solved this in the end by the following
{{ $jj := .Page.URL }}
{{ range $index, $num := (seq .Params.num) }}
div class=“carousel-item” img src="{{ $jj }}/images{{ $num }}.jpg">/div
{{ end }}

Using 32 bit version of Hugo who situation is hard to track down because Hugo gives different error messages.
Error reporting is overwritten or stack is confused.
Easy to find when making a shortcode page like this to test variable transfer to shortcodes…~
Gave inconsistent results!!! Bold is my stuff.

The answer to dot is worth a look…

Dot! (.) is {{ . }}
counter: {{ .Params.counter }}
located: {{ .Params.located }}
sublocated: {{ .Params.sublocated }}
Page.Description: {{ .Page.Description }}
Page.Section: {{ .Page.Section }}
Page.URL: {{ .Page.URL }}
Page.Pages: {{ .Page.Pages }}
RelPLink: {{ .Page.RelPermalink }}
Page.Summary: {{ .Page.Summary }}
BaseURL: {{ .Site.BaseURL }}
Page.Data: {{ .Page.Data }}
Page.WordCount: {{ .Page.WordCount }}
Page.Keywords: {{ .Page.Keywords }}
Page.Kind: {{ .Page.Kind }}
Page.FuzzyWordCount: {{ .Page.FuzzyWordCount }}
Page.ReadingTime: {{ .Page.ReadingTime }}
Page.Params.categories: {{ .Page.Params.categories }}
Page.Params.tags: {{ .Page.Params.tags }}
Page.Pages: {{ .Page.Pages }}
Site.Pages: {{ .Site.Pages }}
Page.Content: {{ .Page.Content }}

The site is called hothammok.com and page source shows the hugo partials as all modules have their name commentedstrong text
I hope that is of some interest in the scheme of things.
It is my first hugo site, now that the thing is working making significant layout changes is so fast.
Thanks again to the creator of Hugo and all those other contributors.
I may get inspired to make a page of my stumbling points along the way …
The design flow was not evident initially.

1 Like

I had some stumbling blocks myself to climb over. I’m glad you got it sorted out. Thanks for the kind words! :slightly_smiling:

Could you help us make the design flow more evident/obvious? Thanks.