I want a list.html for the fotos folder and then a single template for the countries. If I understand it right.
I get the following error:
render: [de v1.0.0 guest] failed to render pages: render of "D:/Code/example_2027/content/de/fotos/_index.md" failed: "D:\Code\example_2027\layouts\fotos\list.html:9:17": execute of template failed at <.thumb>: can’t evaluate field thumb in type page.Page
Hard to get something to recommend, if you cannot describe what you want.
maybe visualize how the result should look like on these pages.
So before I recommend anything I do not understand how your _index.md and the COUNTRY.md’s relate together.
maybe these questions could help you to formulate or visualize your requirements.
what should be displayed on the _index page:
a list of countries each represented by maybe
a headline, one teaser image,
a link to the actual gallery for that country.
or
all images of all countries
or is it just one page showing all images?
what should be on each of the country.md files?
all the images for a country ?
any additional info for each image
or
is that not related to your issue and something different
where are the fotos of each country?
do you want to automatically list all images or manually maintain which images , order, …
and whats that shortcode?
btw you code ranges over pages and the params are on the list page so $.Params.gallery.deutschland.thumb should work … but I guess that’s not really what you want (see above)
and see below the list of related pages to your issue
In the _index.md file I want one image from every country and if I click on it then go to all images of that country. My images are stored in the static folder and I want to choose the order of the images.
That is what I have in germany.md:
+++
draft = false
title = 'Fotos Deutschland'
description = 'Fotos aufgenommen in Deutschland von M.'
[params.gallery.deutschland]
headline = "Germany"
gallery_section = "deutschland_section"
[[params.gallery.deutschland.images]]
caption = "Germany - Foto #1"
thumb = "/images/photos/deutschland/deutschland-01-thumb.webp"
image = "/images/photos/deutschland/deutschland-01.webp"
id = "deutschland_Photo_1"
[[params.gallery.deutschland.images]]
caption = "Germany - Foto #2"
thumb = "/images/photos/deutschland/deutschland-02-thumb.webp"
image = "/images/photos/deutschland/deutschland-02.webp"
id = "deutschland_Photo_2"
[[params.gallery.deutschland.images]]
caption = "Germany - Foto #3"
thumb = "/images/photos/deutschland/deutschland-03-thumb.webp"
image = "/images/photos/deutschland/deutschland-03.webp"
id = "deutschland_Photo_3"
+++
{{< gallery "deutschland" >}}
{{< modal >}}
if you need additional stuff between the galleries than code put the code in shortcoddes.
the gist is - move all of the country properties to the gallery itself for a single point of true
changes to germany only need to be done in one file. and will be pulled in by the main _index automatically
something like:
_index.md
+++
draft = false
title = 'Fotos'
description = 'Fotos aufgenommen von M.'
+++
layout for _index.md
{{/* maybe use .ByWeight (define on the pages) , maybe sort alphabetical or a simple list for full control*/}}
{{ range .Pages }}
{{/* all attributes defined on the country page */}}
<h2>{{.Params.Headline}}</h2>
{{ with index .Params.gallery (sub .Params.teaserImage 1) }}
THUMB: {{ .thumb }}
IMAGE: {{ .image }}
{{ end }}
<a href={{.RelPermalink}}>See all of ...</a>
{{ end }}
germany/index.md
+++
title = 'Fotos Deutschland'
description = 'Fotos aufgenommen in Deutschland von M.'
[params]
headline = "Germany"
teaserImage = 1
[[params.gallery]]
caption = "Germany - Foto #1"
thumb = "/images/photos/deutschland/deutschland-01-thumb.webp"
image = "/images/photos/deutschland/deutschland-01.webp"
id = "deutschland_Photo_1"
[[params.gallery]]
caption = "Germany - Foto #2"
thumb = "/images/photos/deutschland/deutschland-02-thumb.webp"
image = "/images/photos/deutschland/deutschland-02.webp"
id = "deutschland_Photo_2"
[[params.gallery]]
caption = "Germany - Foto #3"
thumb = "/images/photos/deutschland/deutschland-03-thumb.webp"
image = "/images/photos/deutschland/deutschland-03.webp"
id = "deutschland_Photo_3"
+++
layout for germany/index.md
<h2>{{ .Title }}</h2>
{{ range .Params.gallery }}
caption: {{ .caption }}
...
{{ end }}
if your images really follow these naming convention , you already have an order and can completely automate these.
I would move or mount the images to assets (or the country folder as page resource, to use [rR]esources.get “images/germany/*.webp” (if your images sort order is the display order.
completely untested just an idea: but for the definition in frontmatter have a look at resources metadata in frontmatter
where you can map page resourcses to names/and attributes
maybe of target … missing lot of context with your actual intention
and accessed with {{.Params.Headline }} in both partials.
same for the teaserImage
to access the gallery entries from within the range inside the main index file use .Params.gallery use index for individual images and then access the fields.
c’mon @malde11 you are not a fresher so I thought that one would do especially as I wrote I have updated the code.
Blindly copying some snippets to yours is mostly not a good idea.
have a look at the complete picture of my post above
one list page / one gallery example page
two layouts.
check out the front matter and how it relates to the code
hint: [[params.gallery]] is a slice of maps (you set it up)
I leave it up to you why there’s a sub statement in my code
regarding missing english. Check if all is really set up as for the german page. without having the source no way.
and again if one is working I thought you are able to duplicate. if not show your code (gallery + pages)
HINT: code defensive. The shown code works, but is for the gist not a – production ready – fail safe – theme layout code. No error/empty checking at all
And for the English version I have got a _shortcode, but I do not understand all of them:
{{/*
Renders the content of the current page's translation in the specified language.
@param {string} The language key of site from which to retrieve the translation.
@returns {template.HTML}
@example {{< content de >}}
*/}}
{{ with $sourceLanguage := .Get 0 }}
{{ if eq $.Page.Language.Lang $sourceLanguage }}
{{ errorf "The positional parameter passed to the %q shortcode must not be the language key of the current site. See %s" $.Name $.Position }}
{{ else }}
{{ with index (where $.Page.Translations "Language.Lang" $sourceLanguage) 0 }}
{{ .Content }}
{{ else }}
{{ errorf "The %q shortcode was unable to find a %q translation of the %q page. See %s" $.Name $sourceLanguage $.Page.Path $.Position }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "The %q shortcode requires a positional parameter indicating the source language key. See %s" $.Name $.Position }}
{{ end }}
I understand that if I write: {{< content de >}} to an English markdown file, he will take the content from the German version. So both have the same content.
Here is an example of the English _index.md:
+++
draft = false
title = 'Photos'
url = 'photos'
description = 'Photos taken by M.'
+++
{{< content de >}}
But somehow it is not working for the fotos folder.
i used the position to not have to duplicate the path and full access to all the params for that image… question of maintainability.
the code looks like something for a multi language site. you never mentioned and no sign in your examples that germany is more than the location where the picture was taken…
so without real multi lang setup that is not the code you are looking for