SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    0 Post(s)
    0 Thread(s)

    The most flexible way to implement a sidebar in a View?

    Let's say your entire site uses a single template file for layout:
    <title><?php echo $title; ?></title>
      <div id="content">
          <?php echo $CONTENT; ?>
      <div id="content">
          <?php echo $SIDEBAR; ?>
    Inserting the $CONTENT section is easy enough, because it will always be required on every page, but the sidebar may 1) not be required on certain pages, and 2) will be different depending on the page.

    I'm having difficulty grasping the best method to go about implementing a sidebar.

    For instance, should I include a sidebar.tpl template and just perform a bunch of conditional checks:

    PHP Code:
    if (is_homepage()) {
    } elseif (
    is_articles()) {
    } else {
    // etc, etc, etc

    How do you deal with things such as sidebars or plug in different page widgets?

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    0 Post(s)
    0 Thread(s)
    one approach could be to have the $CONTENT variable contain the sidebar. let the code which generates the $CONTENT variable decide whether it should add the sidebar.

    another approach is to ditch the <div id="sidebar"> and just echo $SIDEBAR
    let the code which creates the sidebar decide how/when to populate that variable with data. for example on some pages, $SIDEBAR would be an empty string, and other others it would contain the html needed.

    yet another approach is to have more than one template.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts