This project has moved. For the latest updates, please go here.

best way of using a sidebar?

Nov 15, 2010 at 8:24 AM

sorry for such a stupid question, but what is the common (or the best) way of using a sidebar. The structure of my website is like the following:

1. Header
2. Navigation
3. Page
3.1. Sidebar (left)
3.2. Content
4. Footer

I defined a page.view to display uncategorized posts as simple pages. Therefor I used $post.body in the page.view to display the content of the post. What I am confused about and don't know is how to accomplish the requirement to keep the sidebar dynamic too. The content of the post is displayed in the content-area, but the sidebar is always "hardcoded" in my way.

What would you advise to me? Using widgets? Using if - else structure depending what page is displayed and change the content of the sidebar (seems not very useful for large websites)? Is there a "use case" or a "best practice" showing that?

Thanks,
Markus

Coordinator
Nov 15, 2010 at 12:26 PM

I wouldn't say there is a "best practice" as there are an infinite number of ways you can accomplish depending on what your end need is. If you want a unique sidebar for each page, here are some ideas of how you could approach it:

  • Create a custom field on the post with a "SidebarViewFilename" and then on the page.view use $macros.LoadThemeView($post.Custom("SidebarViewFilename"))
  • Create a custom field that is a list with your various sidebar options and then do the above (if you want a finite number of sidebar options).
  • Use a convention to do the same: so by convention create sidebar view files called something like page-name.sidebar.view and then on the page.view use $macros.LoadThemeView($post.Name + ".sidebar.view")
  • Use if - else structure within sidebar.view 

Those are just some of my ideas. There are numerous other options, it really just comes down to how you would like to have your project structured and options available to admin/content managers.

Coordinator
Nov 16, 2010 at 4:56 AM

How is your sidebar dynamic exactly? Without a little more context, I wouldn't really know how to help you out. Madkidd's idea's are all great, and the best that any of us could provide without more info. If one of those works for you, great, but if not, let us know and if you can, provide some more info. We're glad to help out.

Nov 16, 2010 at 3:25 PM

It also depends on how much you want to control in your admin and how volatile your sidebar data is. In our case we use version control for all out static files so most of the time it makes sense to keep everything in the files. If you are building a navigation, I highly recommend using the built in navigation tool in combination with custom fields if you have hundreds of pages.

There is a extension floating around that will allow you to load a widget by its name so you can add it to your theme and wrap it in a condition. This can be useful if you want to reuse the same one for multipule pages, if the content is unique for every post then a custom field for that category is prob the best. I have sometimes used it for my footers so we can go in and make a change in a second. Like I said it is a case by case scenario.

 

In this case:
http://www.elearners.com/guide/

-Navigation is managed in the built in Nav tool and has custom fields for each post to turn them on or off
-Footer is a widget
-Carousel is a widget
-Sidebar is a combination of widgets hard coded HTML
-Header is a combination of widget data and hard-coded HTML

* Notice I was easily able to put the Featured Students at the top for all the student's pages.
http://www.elearners.com/guide/featured-students/bill-hurd/

Now keep in mind we have a load balancing server and pushing files live is a pain in the ass so I chose to create widgets out of items that would change the most. As soon as something changes I evaluate whether or not it should become a widget or added to the admin in some other way.

Good Luck!