Generate the database-driven menu in the Dreamweaver template

As said earlier, before creating and adding content to the site pages, you need to create a template file in Dreamweaver that will include the site menu.  You will use this template file to later on create all the site pages (so that the menu will show in each one of them).

To create the Dreamweaver template, follow the instructions below:

  1. From the File menu in Dreamweaver, choose the first option, namely New (or press Ctrl+N in the newly created site).  A dialog box with two tabs will pop-up. You only need to set some options in the first tab (General):


                                       

  2. What you need to do next, before continuing with the actual template, is to create a Dreamweaver database connection.  Use the Databases tab of the Application panel to define it.  Name it conn_other_table, configure it to connect to your database server, and make it point to the database containing the table previously described.

  3. The site menu that you will generate in the template file will retrieve the labels for the second level menu items (corresponding to one of the first level items) from the database, more precisely from a recordset.  Create this recordset now to retrieve the products names.  Go to the Application panel, Bindings -> + -> Recordset (Query).  Configure the dialog box that opens as shown below:


                      

  4. After clicking OK in the Recordset dialog box, the following message will pop-up:


                      
    Click OK to close the alert window.  You will be told how to make the code corresponding to the recordset (added above the <html> tag) to be seen in the pages based on this template.

  5. Press Ctrl+S to save the changes made in the template file so far.  Since there is no editable region in your template file yet, you will be asked for confirmation first if you really want to save the file:


                      
    Click OK as you will add the editable region below.  In the new dialog box that opens enter the name by which you want to save the template file - other_table_tmp, and click the Save button:


                      
    Notice in the Files tab of the Files panel the Templates folder automatically generated by Dreamweaver, and the template file you just created located inside this folder.

  6. It is now time to add the site CSS menu.  Remember that the menu items on the first level are entered manually and the ones on the second level (corresponding to one of the first level items) are retrieved from the database.  Apply the CSS Menu Wizard from the InterAKT tab of the Insert bar.  The wizard has three steps.

  7. Configure the first step of the wizard as shown below:


                      

  8. In the second step of the wizard you get to enter the items of the CSS site menu.  Start with the first-level items (Home, Spring Pack, Company), and then continue with the sub-items for the Spring Pack item. Configure the user interface as shown below:


                      

  9. Configure the third step of the wizard as shown below:


                      

  10. After following the steps above, the other_table_tmp.dwt page in Dreamweaver, in Design view, should look like this:


      
    Place the cursor inside the Spring Pack menu item displayed in the translator, and select (click) the <li> tag in the Tag Selector.  Switch to Code view and notice the selected code corresponding to the <li> tag:

    <li> <a href="../spring_pack.php" title="Spring Pack">Spring Pack</a>
    <ul>
    <li> <a href="../products.php?id_prd=" title="Products">Products</a> </li>
    </ul>
    </li>

      
    In order for the sub-items of the Spring Pack menu item to be retrieved dynamically, perform the following operations inside the <li> tag from the <ul> one in the selected code:

  11. After performing the three changes above, the code section should now look like this:

    <li> <a href="../spring_pack.php" title="Spring Pack">Spring Pack</a>
    <ul>
    <li> <a href="../products.php?id_prd=<?php echo $row_rsProductsNames['id_prd']; ?>" title="<?php echo $row_rsProductsNames['name_prd']; ?>"><?php echo $row_rsProductsNames['name_prd']; ?></a> </li>
    </ul>
    </li>

     
    At this moment though, only one menu item is retrieved from the recordset.  To make all the dynamically-retrieved items show you need to apply a repeat region.  Select the line of code you just modified (including the opening and closing <li> tags), and from the Server Behaviors tab of the Application panel access the Repeat Region server behavior.  Configure the dialog box that opens as shown below:


                     

  12. The last thing you need to do before the template file is complete is to add an editable region.  Switch back to Design view, click inside the menu translator, and select (click) the <div.horizontal#cssMenu1> tag in the Tag Selector.  Press the right arrow key and then Enter to create a new paragraph below the menu <div>.  This is where you will insert the editable region used to hold the specific content of the pages built based on this template.
    From the Insert menu in Dreamweaver, select the Templates Objects -> Editable Region option:


                           
    In the dialog box that pops-up enter a name for the editable region - content, and then click the OK button:

 

After following all the steps above, the other_table_tmp.dwt page in Dreamweaver, in Design view, should look like this:

 

Notice the elements added in the Server Behaviors tab of the Application panel (recordset, server behavior, dynamic elements).  If you want to edit any of these, double-click their name in the list.  If you want to edit the menu, click inside its translator and use the corresponding Property Inspector.

Note: After creating template-based pages in your site, if you later on make changes in the template file, they will become visible (after refreshing) in the template-based pages only if they (the changes) were not made above the <html> tag.  This means that if you edit the recordset (its corresponding code is placed above the <html> tag) the changes will not become available in the other pages.

Save the other_table_tmp.dwt file (if you haven't already) and upload it to the server.  You can preview it in browser (press F12) if you want to, but the pages to which menu items point are not built yet.

Continue with the next topic to create the actual site pages based on this Dreamweaver template.