Toggling Sidebar On/Off

I have a client that wants to have the option of hiding or showing the sidebar on a per-blog basis. This is easily achieved in Wordpress by changing the blog template to full-width. Is there similar functionality available in the Hubspot blog to choose a different template?

Any other workarounds or ideas are welcome!

Hi @awojcek,

by default you can select different templates for listing and all post view but not for specific posts. ( Author- and Tag-pages are inside the listing view by default)

Here some ideas for workarounds:

  • create a simple toggle/toggle module which triggers a jQuery script or CSS class for showing/hiding the sidebar and insert it into the default blog-post view/template. This way the content-editor who will write/post the blog post will have the option to enable or disable the sidebar on post basis. Don’t forget to change the col-size of the post if you’re using bootstrap or another gridsystem. Something like this:
{% if module.enable_sidebar %}
<script>
$('.sidebar').show();
$('.content').removeClass('.col-md-8').addClass('.col-md-12')
</script>
{% endif %}
  • Never done that but you could try to create a choice option module where you can select multiple post templates. The value of each option should be after “==”. I’ve named them just 1,2,3. If you’re writing your own post-template and you want to have a cleaner code you could think about creating a partial for every option and paste it between the selectors
{% if module.post_layout_selector == 1 %}
{# paste your whole first layout here #}
{% elif module.post_layout_selector == 2 %}
{# paste your whole second layout here #}
{% elif module.post_layout_selector == 3 %}
{# paste your whole third layout here #}
{% endif %}

best,

Anton

Thanks for your help Anton! Yes, we later found this post outlining how to create a toggle and I think that’ll be our best bet moving forward.