Hugo

[SOLVED] Remove something from some certain pages?

Hi there. I want to ask you guys how can I prevent some contents from being displayed in certain pages like I’ve Disqus comment section which I don’t want to see on ُُPrivacy Policy. Similarly, I don’t want to see some other stuff like social sharing button addtoany. How can I hide them where I want.
I’m new to hugo and this is my first help call so please be gentle and explain the solution.

You could add a boolean param to your config file, or to page front matter. Then in your template, check that param. For example, if going the per page route:

{{ if ne .Params.show_comments false }}
  // code to show comments here
{{ end }}
1 Like

Below is my social sharing buttons list which I obtained from addtoany.com

<div class="a2a_kit a2a_kit_size_32 a2a_default_style"> <a class="a2a_button_facebook"></a> <a class="a2a_button_twitter"></a> <a class="a2a_button_whatsapp"></a> <a class="a2a_button_linkedin"></a> <a class="a2a_button_google_bookmarks"></a> <a class="a2a_button_pocket"></a> <a class="a2a_button_email"></a> <a class="a2a_button_sms"></a> <a class="a2a_button_print"></a> </div>
You mean, I’d enclose it within
{{ if ne .Params.show_comments false }} // list here {{ end }}
and on every page front matter I’ll declare it ‘false’?
I request you please, can you one write a code for it? IDK how to write this kinda scripting.

The example I gave was for comments. You would do something similar for social sharing buttons. Like this in your front matter:

---
show_social: true
---

Thanks sir I got it. :grinning: :+1:
Now I’m feeling like Hugo community is super cool.

Glad to hear :+1:

Sorry for disturbing again.
I want to ask you that what’s the difference between both of these if states:
{{ if isset $.Site.Params "bgimg" -}} // code stuff {{- end }}
vs
{{ if isset $.Site.Params "bgimg" }} // code stuff {{ end }}
Note the hyphen. Is this the same thing or different. I curious because I saw it theme and it also work.

They control white space. See https://gohugo.io/templates/introduction/#whitespace