Jump to content

(Solved) Sidebar


mrs
 Share

Recommended Posts

Hi all,

Installation done and multilingual has been implemented successfully but I faced a problem.

I cloned the basic-page, named it basic-page_noside and deleted the "sidebar" at the template setting.

I use this new template for the "Docs" page under the Home, and also two child page under "Docs".

However, I still can see the sidebar content when I view Docs and the two child pages.

I think I miss out something.... and need your help on this.

I don't know much about coding etc. but I could follow instruction well. :)

Link to comment
Share on other sites

Have a look at the code in the file head.inc that is in the templates directory:

<div class='sidebar_item'>
 <?php
 // if the current page has a populated 'sidebar' field, then print it,
 // otherwise print the sidebar from the homepage

 if($page->sidebar) echo $page->sidebar;
 else echo $homepage->sidebar;
 ?>

</div>
</div><!--/sidebar-->

head.inc is included by the basic-page.php template file.

<?php
/**
* Page template
*
*/
include("./head.inc");
echo $page->body;
include("./foot.inc");

You can:

a) copy and paste the contents of head.inc into a new file. Delete the sidebar code i showed above and save it to head_noside.inc or whatever you like. Afer that change basic-page.php contents to include("./head_noside.inc"); Be aware, keep the other code in there the same.

b) Make some logic in head.inc to not output the sidebar if the page template is basic-page.php.

c) alot of other options

  • Like 2
Link to comment
Share on other sites

Thank you SiNNut for the pointer.

I changed the code so that it will not print sidebar of homepage and everything is well.

I thought Setup -> Templates is letting us change the template immediately, but it seems like it is just not showing the fields for inputting content purpose... Probably I get too used to those "widget" style that I think when I get rid of the "sidebar" field for that template, the sidebar would be gone. :P

Link to comment
Share on other sites

It's important to remember that in ProcessWire a Template and a template fileare two separate things.

In Setup->Templates you create and manage Templates. You can add fields to a template, do some access settings etc. The fields you add to the template are shown in the admin when you create a new page with that template. The order in which they appear is controlled by the template settings (drag and drop).

A template most of the times has a template file associated with it, but it isn't necessary. In a template file you have complete control over the output and logic.

If you have no need for a sidebar field at all you could go to Setup->Fields and remove the 'sidebar' field.

(ofcourse, you then probably would want to remove references to that field in your template codes.

  • Like 2
Link to comment
Share on other sites

Wow, thank you for the detail explanation.

I would go read further to understand the template setting and template file. :)

I need the sidebar, but not for all page, as when you have the children page with navigation menu at the sidebar area, the content of sidebar let's say from the homepage would push further down which looks weird to me.

Link to comment
Share on other sites

No problem,

Study the docs section; maybe do the Small Project Walkthrough and just read through the code in the files of the templates dir. They are well commented and you really see what's going on. When you become more comfortable with some basic PHP + ProcessWire's API it's time to have the cheatsheet standby.

You'll be flying in no time.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...