SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    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:
    Code:
    <html>
    <head>
    <title><?php echo $title; ?></title>
    </head>
    <body>
      <div id="content">
          <?php echo $CONTENT; ?>
      </div>
    
      <div id="content">
          <?php echo $SIDEBAR; ?>
      </div>
    </body>
    </html>
    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()) {
        include 
    'homepage_sidebar.tpl';
    } elseif (
    is_articles()) {
        include 
    'articles_sidebar.tpl';
    } 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
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    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.


Bookmarks

Posting Permissions

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