Z
Z
zx5zx62020-09-18 17:55:28
HTML
zx5zx6, 2020-09-18 17:55:28

HUGO site generator: How to use the data from the YAML config file in an HTML page located in the static folder?

A site that is written in HUGO must consist of two pages.
5f64c7abd3dfe161229115.png

First (index.html) - The main page that is displayed when the HUGO server is up.
All data, such as photos, links, navbar elements, etc., is stored in the YAML config.
Uses standard HUGO syntax for config variables, like {{ variable }}.
Everything is displayed as expected.

config snippet:

navbar:
  - title: How does it work
    url: '#section-how-does-it-work'
  - title: For partners
    url: /html/index2.html/


html snippet:
<div id="for_guests">
      {{ if .Site.Params.hero }}
      {{ partial "hero.html" . }}
      {{ end }}

      {{ if .Site.Params.section1 }}
      {{ partial "section1.html" . }}
      {{ end }}
</div>


The second one (index2.html) is located in the static folder, since, if I'm not mistaken, you can only refer to files
located in the static folder.
The code is identical to index.html with the same syntax for config variables.
This page does not see the config and therefore displays all attempts to use variables from the config as a normal string.
5f64c9e8dd102861991738.png

Question: How to use the config data in the html page located in the static folder?
If there is an alternative way to add a second page in the HUGO generator, that might help me too.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question