Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Throughout this chapter, we have used Dreamweaver's Spry elements to quickly and easily add Spry content to our pages. Like all the processes the Dreamweaver assist us with, it is always good to know how to do some of these effects ourselves. So in this exercise, we'll hand-code a Spry region that will display a listing of past shows by the author. Along the way we'll see some of the ways that Dreamweaver can assist us in hand-coding our Spry as well. Our first task will be to add a new data source. Our existing data source does not have information on past shows. So we are going to need another one. In our previous exercise, where we added a data source, we did that using the Spry toolbar and Insert > Spry Data Set icon is the first icon on the toolbar. Well, there are other places where we can get this as well and we'll go ahead and explore that in this exercise.
Go to your Application panel, and in your Application panel, you will see your Bindings panel. We have already used the Bindings panel in our previous exercise, when we were placing our dsShow information on the page. So if you are following with us with the exercise files, you should see this data source, dsShow. To add another data source, just go up to the plus symbol in the Bindings panel in the upper left-hand corner, click on that and you will see where it says Spry XML Data Set. So here is where we can add another data set. So, we'll go ahead and select that. We are going to give this set its own name and we will call it dsPastShows. So we try to be descriptive with how we name our dataset. So, the last one was dsShow. This one is dsPastShows and that gives us a little bit of information about what is in of these datasets.
So, I now need to browse to my XML file. So, where it says XML source, I'll click the Browse icon beside that. Browse to the _xml folder in the Chapter 5 Exercise folder, and you want to find the XML file pastShows.xml. Go ahead and click Choose, or Select. And you want to click the Get schema button, so that it will parse the XML and display the data that contained within. For the Row element, we want to choose show. That's a repeating element and it contains the date the show was held and the name of the show.
Now, if I go down to my Data Set columns, it shows the show, date and name; they are all string types and we don't need to change those. I am going to sort them and I am going to sort them by date. One of the things that we can do is preview our XML data source. So if I choose Preview, I see a table representing the information that we are going to bring in. Notice that because we are sorting by date, Spring of 2002 is listed first; Spring of 2006 is listed last. So I'll click OK. You could change that order if you'd like to ascending or descending.
So I'll click OK to build of the dataset and when I do that, my Bindings panel now displays two datasets, the dsShow and the dsPastShows. So. I am going to collapse the dsShow just to avoid any type of confusion and I will leave the dsPastShows open. Notice that we have the show, the date and the name. Okay well, we are going to hand-code this. so we are going to go in the Code view and where we are going to locate these is just below the table that contains the painting and the price information. Rather than just switching over to Code view and having to scroll down to find that information, I am going to click inside of that table.
Now I can use my Tag Selector to let me know exactly where this content is and we actually want to place our content directly underneath the div tag that contains this table. If you look your Tag Selector, you'll have an idea as to why that is. Dreamweaver is going to highlight any tag element that contains Spry data with that light orange highlight. You don't want to try to place competing regions inside of each other because that can confuse the data that's output on the page. So since that containing div tag already has a Spry region, we are going to need a new Spry region. So we are going to locate just below that.
So, I am going to click on the div tag that contains the table that will highlight it. Now, when I switch over to Code view, that code's highlighted and it's very easy for me to scroll down and to tell exactly where I need to add my new region and that would be right between Line 60 and 61. So, I will select Line 60 right at the end and hit Return to go ahead and give myself a new line. One of the rules about adding Spry regions is that Spry regions are typically contained within a div tag. So that's the first thing we are going to add. So I am going to go ahead and type in a div tag, and after I type in the div, instead of giving it an id, I want to type in s and notice that Dreamweaver gives me all these Spry code hints. Instead of continuing the type, I am just going to mouse down the menu that comes up and what I am looking for is the Spry region. So I am going to choose spry:region.
After you choose region, Dreamweaver wants to know which dataset should I pull information into this region. Well, we are going to choose the dsPastShows. So dsPastShows, I am going to end my opening div tag, I will hit Enter and then I will close out that div tag. So now we have a div tag, it's a Spry region and it's pulling information from the dataset that we've just created. Let's get to the next line inside the div tag, and I am just going to go ahead and add an h2 tag. And inside the h2 tag, let's type in Past Shows, and we'll close our h2 tags. So what it will do is Spry there.
Now on the next line, we are going to add an h3 tag, and the h3 tag is going to have some Spry data in it. Now, if you want, you can use your Bindings panel in Code view. For example, the first thing that we want inside this h3 is the name of the show. So, I could go up to my Bindings panel, I could select to that name and I could literally drag and drop it into my code right where I want it. Now I don't have to do that and as a matter of fact, this explicit dataset path that we have really isn't even necessary. Since we've describe the dataset in the region, we don't really need the dsPastShows::@name. As a matter of fact, we can just go ahead and delete that and leave in the curly braces, the @name.
It will know which dataset to pull it from because it's inside the Spry region. I'll hit space and what we'll do now is we'll do a little line break. So go ahead and do a line break tag. Remember to self close that line break because we are using XHTML. I am sure everybody is familiar with the line break. That's just going to break us down on to the next line and then I am going to throw a span tag in, and inside the span tag, I am just going to hand-code some Spry, I am going to type in a curly brace and then watch what happens when you type in a curly brace.
Dreamweaver says oh hey, I see that you are inside of a Spry region and you typed in a curly brace, so you must want something from that particular dataset, what would you like? So if I type in an @ symbol, there it jumps right down to @date. That's what I am looking for, so I'll hit Enter and it finishes that for me. So even when you are hand-coding Spry, Dreamweaver is very intelligent about adding items to your page. We'll go ahead and close out the h3 tag and there is one more thing I want to do. If you can sort of imagine what this is going to look like in your head, we are going to have an h3, the name is going to show up, there will be a line break and directly underneath that will be a date. Now we put a span tag around that date, so that we could use CSS to style the date separately from h3.
I also want an Em Dash directly after the name. So what I am going to do is place my cursor right beside the name and you could type in the encoding for the Em Dash if you know what that is. but if you don't, you can also go up to your Insert toolbar, click on Text and then on the far right-hand side, you will have a little pulldown menu. You might not see the same character that I do, but if you just grab the pulldown menu, you can grab Line Breaks, Non-Breaking space, Quotes. I am going to choose Em Dash and it enters the encoding for it. Now at this point, if we preview at our page, it would work and we would see the past show, we would see a name, we would a date, but we would only see the first one. So we need to go ahead and add a repeating region.
Now remember, you don't want everything to repeat. As a matter of fact, the only thing that we want to repeat at this point is the name and the date. So with h2, the title Past Shows is not going to be part of the repeat region. So I am just going to highlight my h3. You can get a lot of information from prior content. So if I look up the code to Line 55, there is a repeat region in the table row and it says spry:repeat = and of course, we have the dataset. So you can see code examples of how things work by using Dreamweaver's Insert tools and then examining the code and kind of see how it works.
But we are going to wrap this in a div tag because your Spry repeat attribute needs to be on at repeating element. So I am going to go ahead and click the Quick Tag Editor, and we'll go ahead wrap this in a div tag. And in the div tag, I am going to choose Spry and I'll scroll down and choose repeat. And inside the repeat, I'll type in the dsPastShows dataset and I'll hit Enter and now, my h3 is wrapped in a div tag. So just double check you code to make sure that the h3 is fully wrapped in that div tag.
We'll save the file, and at this point, we can switch back to Design view and if you scroll over, you kind of get a good feel for what it is that we are going to see. There is the name and underneath that is our date. So we'll go ahead and test this in our browser, and as I scroll down, here we go, we get a listing of our past shows and notice that our repeating region is just showing all of our past shows. I hope you've enjoyed learning about Adobe's Spry framework. Adding AJAX to your site, doesn't have to be time consuming or difficult, and I hope you'll continue to explore all the ways that Dreamweaver's Spry framework can enhance your sites.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.