Hi there,
Is there a way to use the /data folder in a multilanguage website, eg. using a data-name.en.json and data-name.fr.json file ?
Otherwise, what would be the simplest way to create an array of multi-level data within the en-Us.toml and fr-FR.toml in the /i18n folder ?
Thanks in advance.
Regards .
bep
July 28, 2017, 7:22pm
2
You could do something like this:
{{ $data := index .Site.Data (printf "mydata_%s" .Site.Language.Lang ) }}
1 Like
Hi,
thanks for your help!
{{ range $index, $val := .Site.Data (printf "faq_%s" .Site.Language.Lang ) }}
I tried this but it’s not working - I got the following error:
<.Site.Data>: Data has arguments but cannot be invoked as function
Any idea?
Thanks.
bep
July 29, 2017, 4:55pm
4
You have to follow my example and not make up something completely different.
Following advice from @bep , I did it this way and it works perfectly
See it here in action: https://moodlebox.net/
1 Like
bep
April 21, 2018, 5:26pm
6
This is curiosity; But would the above be the same as:
{ if $testimonials }}
Which could then be rewritten to:
{ if with $testimonials }}
I’m to lazy to try … @kaushalmodi may know.
Yes it works!
What would be the difference with
{{ if with $testimonials }}
bep
April 21, 2018, 7:14pm
8
Should would be less verbose:
{{ with index .Site.Data.testimonials .Site.Language.Lang }}
{{ range . }}
// Do something with tesimonial here
{{ end }}
{{ end }}
1 Like
bep:
if with $testimonials
Pretty sure that this is a typo as I have never seen if
+ with
.
But yes, always a fan of with
So:
{{ with $testimonials }}
I don’t understand: this works: {{ if $testimonials }}
but this
kaushalmodi:
{{ with $testimonials }}
throws an error in my partial:
theme/partials/testimonials.html:14:50: executing “theme/partials/testimonials.html” at : wrong number of args for markdownify: want 1 got 0
Any idea?
Edit :
Found it, sorry for my dumbness : forgot to change .Site.Params.testimonials.title
to $.Site.Params.testimonials.title
.
1 Like
Current version with with
. Thanks @bep and @kaushalmodi .
Visit https://moodlebox.net/ to see it in action.
1 Like
And when the data is in one file:
data/
dataname/
en/
dataname.yml
fr/
dataname.yml
{{ with index .Site.Data.dataname .Site.Language.Lang }}
{{ range .dataname}}
<a href="{{ .URL }}">{{ .Name }}</a>
{{ end }}
{{ end }}
2 Likes