5 Steps to Adding Sidebar Block in Zen-Cart

You may find that you want to add a block to the sidebar in Zen-Cart. The content may be text, image, or other feature to extend the content on the cart. The generic concept of adding a block involves 5 steps. This article explains the steps. For simplicity, we will only add a text block.

Step 1; Create Sidebox Template

Add a new file to the server in the following directory: /includes/templates/<template-name>/sideboxes/. Name the file something relating to the contents of the sidebox. We will be adding a support phone number to call in a sidebox, so, we might name the file tpl_support_number.php. The file will include what you want to display in the box and will be assigned to the variable $content variable. Below is an example of the contents of the file.


  <?php
     /* Side Box Template  */
     $content = "For information about products or services, call (888) 555-1212" ;
  ?>

Step 2; Create Sidebox

Now, to create the actual box; add a new file to the server in the following directory: /includes/modules<template-name>/sideboxes. Name the file something relating to the contents of the sidebox. In our sample, we will call it support_number.php. The contents of this file will look like the sample below, but, modify the variables to relate to your template.


  <?php
  /**
   *  Support Number Sidebox - used to display a support message 
   *  in a sidebox.
   *
   */
   $show_message = true ;
   if ($show_message == true) {
       require(
         $template->get_template_dir('tpl_support_number.php', 
            DIR_WS_TEMPLATE, $current_page_base,
           'sideboxes') . '/tpl_support_number.php');
       $title = BOX_HEADING_SUPPORT_NUMBER ;
       $title_link = false;
       require($template->get_template_dir($column_box_default, 
           DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . 
           $column_box_default);
   }
  ?>

Step 3; Add Language Variables

Modify the english.php language file in /includes/languages/ to include the definitions for any text variables you have used in either file. In this example we created a new variable called BOX_HEADING_SUPPORT_NUMBER. So, we will add the following to the english.php file.


  // welcome box text in sideboxes/welcome.php
  define('BOX_HEADING_SUPPORT_NUMBER', 'SUPPORT INFO');

Step 4; Enable Sidebox:

Activate the sidebox as follows:

  • Login into Zen-Cart administration.
  • Hover over Tools.
  • Select “Layout Boxes Controller” from the drop down, a list of boxes will appear …  including your new box
  • Double-click the name of the new box you have created, in this sample, it will say …  sideboxes//support_number.php. In the upper right of the window you will see fields that you can edit.
  • Select to edit the information, an editable form will appear
  • Fill in the form, by:
    • Selecting the radio button next to “on” in “Left/Right Column Status”
    • Selecting the radio button to place the box on the “left” or “right” sidebar
    • Typing the correct number is the sort order field to display the box
    • and then clicking the Update button.

The sidebox is now enabled on the site

Step 5; Verify Sidebox:

Now, visit your store in a browser and make certain the sidebox displays.

 

Leave a Reply