Multilingual site home page button

Hello,

Some of my articles are written in different languages.

Is there a way to make the home button go to the homepage of the same language?
i.e. If I were reading a French article with the URL $base/fr/article, clicking on the home button would get me back to $base/fr instead of $base.

Currently, the home button reads the config file for entry config.extra.logo_home_link.
I added the following to my config.toml, but it didn’t work.

[languages.fr.extra]
logo_home_link = "$base/fr"

I also thought about adding an index.fr.html in templates/ but it doesn’t seem to be the most modular option, nor do I know if it would work.

Thanks a lot for the zola project, have a nice day :slight_smile:

1 Like

You can use the lang variable.

I did the following:

<a href=“{{get_url(path=”“, lang=lang)}}/” class=“brand-logo left”>{{ config.title | safe}}

And please tell me that config.title doesnt work for you. Since i feel its a bug

I’m not sure how to do that. I can’t really wrap my head around the macro language Zola uses, and I can only find short codes in the documentation. Are they the same thing?
I don’t really know how to adapt your solution to my case, since I don’t understand the macros.

Thank you :slight_smile:

Shortcodes are essentially single file templates. It’s not the same as macros although it does look a bit similar.

That is neither short code nor macro. You need to understand the templating concept here.

Try the following in base.html file under templates

<a href= “{{get_url(path=”“, lang=lang)}}” > TITLE

The use of lang=lang functions because of the following variables available on each page

A few variables are available on all templates except feeds and the sitemap:

  • config: the language aware configuration
  • current_path: the path (full URL without base_url) of the current page, always starting with a /
  • current_url: the full URL for the current page
  • lang: the language for the current page

And you dont need the following:
[languages.fr.extra]
logo_home_link = “$base/fr”

I tried to do that, but it seems like my website doesn’t follow the template when it’s in another language other than the one defined in the config.toml?
The link only shows up when I view base_url/ in a browser, if I try to view base_url/fr the link disappears.

image
image

Do I need to have multiple index.html for each language?

Thank you!

I was able to change the link of the home button, thank you!

I ran into another related issue earlier, I wanted to use a for loop to create links in the home page.

<div class="site-langs" style="opacity: .5;">
  <span>Language: {% for lang in config.languages %}<a href="test">Some text</a>{% endfor %}</span>{# TODO translate the span content too #}
</div>

Zola says “Tried to iterate using key value on variable config.languages, but it is missing a key”.
What key is missing? Is it possible to iterate over the languages variable defined in config.toml like this?

Thank you!

No you dont need different index.html files.

Just print out the value without use a link. {{get_url(path=”“, lang=lang )}}

True, this works. Thank you!

I do want to know if there’s a way to do this with a for loop though, since it would be more modular, and it would follow the changes in config.toml.

Thank you!

what do you mean. test out each language?

the lang variable will not work in a loop. it will remain the same value

but one can do loops in tera language.

for example in the index.html file you can do the following i think. which should print out info re the blog pages in the section.

  {% for page in section.pages %}
  {{ page.permalink | safe }}, {{ page.title }} {{config.extra.whatever}}
  {% endfor %}