Ask Your Question
4

How can multiple sections be conditionally displayed in Hugo?

asked 2022-09-10 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-12-31 23:00:00 +0000

nofretete gravatar image

You can use Hugo's built-in if statement and its with modifier to conditionally display multiple sections in your templates. Here's an example:

{{ if .Params.showSectionOne }}
  <div class="section-one">
    <!-- your section one content here -->
  </div>
{{ end }}

{{ if .Params.showSectionTwo }}
  <div class="section-two">
    <!-- your section two content here -->
  </div>
{{ end }}

In this example, we're checking the value of two boolean parameters (showSectionOne and showSectionTwo) to determine whether or not to display each section. If the parameter is true, the corresponding section is displayed. If the parameter is false, the section is not displayed.

You can adjust this code to fit your specific needs. For example, you could use a different type of conditional statement (such as if eq or if ne) to check for specific values rather than boolean parameters.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-10 11:00:00 +0000

Seen: 20 times

Last updated: Dec 31 '21