How to display photo descriptions

If you want to include your pictures in an AJAX photo gallery and display a short description for each one of them (as a tooltip, when the mouse pointer hovers the picture), you need to have the photo descriptions stored in an .xml file. There are two ways in which you can do this:

  1. Store the photo descriptions in the database and export them in an .xml file as shown below.

    Note:
    Besides MX AJAX Toolbox, there is another Dreamweaver extension you need in order to follow this tutorial, namely XML Import-Export - Try | Buy.
                           

  2. Create the .xml file yourself as shown below.

So, in order to complete this task, you must first come up with the .xml file and then create the AJAX photo gallery.

Create the XML file

No matter if you are using a database or not, here is what you need to do first:

From this point on, regarding the .xml file, follow the instructions below corresponding to your situation.

Create the XML file by using a database

If you want to store the photo descriptions in a database and then export them into an .xml file, follow the next steps:

  1. You need one database table, say image_img, with three columns: id_img, filename_img, and description_img (their names are more than suggestive). Create the database (structure and records) by using the scripts provided in the .zip package (either .sql or .mdb), in the \tutorials\Photo description\db folder.

  2. Open the photo_gallery file and define a new Dreamweaver database connection: conn_photo_desc. Configure it to connect to your database server and make it point to the database containing the table described above.

  3. Create a new file in the site root and name it xml_export. This is where you will apply the server behavior for exporting data from the database.

  4. Open the xml_export file and go to the Application panel, Bindings -> + -> Recordset (Query) to create a recordset. Configure the window that opens as shown below:


                           

  5. Apply the Export Recordset As XML server behavior from the Application panel, Server Behaviors-> + -> InterAKT. The dialog box has two tabs. If so far you followed the exact steps of the tutorial, and if there was no user interface persistence that affected the default settings, the dialog box is already configured as needed:

Save, upload, and preview the xml_export page in browser. You will see the database table records exported in the XML format. You can close the xml_export file.

Create the XML file manually, without using a database

If you want to store the photo descriptions in an .xml file from the beginning, and do not involve any database, follow the next steps:

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


                                         

  2. The new file will open, already having a line of code inside: <?xml version="1.0" encoding="iso-8859-1"?>. Add the XML content below that line, considering these two conditions:

  3. Checking the filenames of your images stored in the photos site folder, you can complete the .xml file with:

    <root>
    <row>
       <filename>Laura.jpg</filename>
       <description>My daughter, Laura, and our dog, Dino.</description>
    </row>
    <row>
       <filename>Dino.jpg</filename>
       <description>Dino playing in the garden.</description>
    </row>
    <row>
       <filename>Winter.jpg</filename>
       <description>Christmas morning in the Alps.</description>
    </row>
    </root>

                                         

  4. Complete the file with a corresponding <row> tag for each image in your folder.

Save the file in your site root under the photo_desc.xml name, and then close it.

Build the photo gallery

Now that the photo descriptions are stored in an .xml file, you can go ahead and build the AJAX photo gallery that displays for each photograph a short description:

  1. Open the photo_gallery file, if not already opened.

  2. Apply the AJAX Photo Gallery server behavior from the MX AJAX Toolbox tab of the Insert bar. The dialog box has two tabs.

  3. Configure the first tab (Basic) of the AJAX Photo Gallery command as shown below:


                                  

  4. Configure the second tab (Advanced) of the AJAX Photo Gallery command as shown below:

Save, upload, and preview the photo_gallery page in browser:

 

Notice how when the mouse pointer hovers the current image or any of the visible thumbnails, the photo description is displayed as a tooltip. If you manually created the .xml file and did not cover all the photos in the site folder, for those without a description, the filename will be displayed as a tooltip.