I need to create 2 templates for pages: "with sidebar" and "without sidebar".

I need to show sidebar for certain pages and hide it for others. This behavior should be configured thru options and not thru code.

How can I make it in Joomla 3.4.1?

2 Answers 2


Quite a simple thing to do. In your template's index.php add the following and change position-8 to whatever position in the sidebar.

<?php if ($this->countModules('position-8')) : ?>
    <div id="sidebar">
        <jdoc:include type="modules" name="position-8" style="xhtml" />
<?php endif; ?>

Basically, what this does is, it detects if there are any modules assigned to position-8 and will display the sidebar only if there are.

You may have multiple positions inside the sidebar, so you can also use:

<?php if ($this->countModules('position-8') && $this->countModules('position-9')): ?>
  • Thank you very much for your reply. Pages "with sidebar" and "without sidebar" have different page structure (different element wrappers) and probably adding module to position and checking if there are any modules for current page is not best choice for my case. Is there way to create 2 different page templates and set one or another for certain pages?
    – Vitalii
    Apr 23, 2015 at 14:53
  • Ahh ok. Is your template a custom template or did you download it?
    – Lodder
    Apr 23, 2015 at 14:58
  • I made custom template from scratch using Joomla docs.
    – Vitalii
    Apr 23, 2015 at 15:00
  • I got it. I will change the wrapper classes using same php condition you provided. And sidebar will be hidden if there is no modules on that position. IMHO it looks pretty tricky but it works for me. Thank you for your help.
    – Vitalii
    Apr 23, 2015 at 15:13

I suggest to duplicate your template from Template Manager and do the modifications (no sidebar) to the new one without messing with the original one.

Then go to your menu and edit the menu item of your choice by selecting from "Template Style" list the duplicated (no sidebar) template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.