Using Library Items


Although snippets enable you to reuse code over and over, and assets provide you with easy access to the various objects within your site, Dreamweaver contains an additional tool that enables you to reuse entire portions of a page that you have created. This tool, known as the Library, provides a place to store commonly used page elements for reuse throughout your entire site. For instance, you can store the entire header for your site in the Library and have each page reference that single Library item. Then, when you make a change to the Library item, all instances of that object within your site are automatically updated. This makes it extremely easy to make site-wide updates.

Just thinkyou can create a Library item that adds a copyright notice to the bottom of each page in your site. Then, you can update the single Library instance of the notice once a year and the entire site is updated.

When you create your first Library item, Dreamweaver generates a Library folder in your local site. This folder contains all the Library items for the site, each of which is identifiable by its .lbi extension.

Although you can edit Library files directly in this folder, the best place to work with Library items is in the Library category of the Assets panel (see Figure 24.7). In this panel, you can create and edit Library items, insert them into pages, and even copy them to another site's library. You can use the horizontal slider to view additional information about the Library item such as size and the path to the Library file.

Figure 24.7. The Library category of the Assets panel displays a preview of the Library items.


Creating Library Items

Creating a Library item in Dreamweaver is extremely easy. Simply add any object or element to the Design view of a page and select it. Next, choose the Library category in the Assets panel and click the New Library Item button (see Figure 24.8). Dreamweaver then creates a Library item based on the selected object and allows you to name it accordingly.

Figure 24.8. The New Library Item button allows you to create a new item.


After the Library item is created, you can apply it to any page by dragging and dropping it into the Design view or by placing your cursor at the appropriate insertion point and clicking the Insert button at the bottom of the Assets panel. When the Library item is inserted, the item is surrounded by markup code (see Figure 24.9) that indicates the path to the Library file, much like a server-side include.

Figure 24.9. When you insert a Library item, the markup for the elements is inserted and surrounded by comment tags. The item appears highlighted in Design view to distinguish it from regular, editable content.


Editing Library Items

As mentioned earlier, the main advantage of the Library is that modifications made to an item are updated site-wide. To edit an existing Library item, select the item in the Assets panel and click the Edit button at the bottom of the panel. Make the appropriate changes to the .lbi file that is opened and click the Save button. When you save the .lbi file, you are prompted to update all pages in the site that contain an instance of the item (see Figure 24.10). If you Click the Update button, Dreamweaver automatically updates the dependent pages.

Figure 24.10. When you save changes to a Library item, you're prompted to update all instances of the item throughout the site.


If you don't update pages at this point, later you can use Modify, Library, Update Current Page or Update Pages. If you choose to update, the Update Pages dialog box appears (see Figure 24.11). You can also use this opportunity to update the remainder of the site's Library and template instances by choosing Update Site from the Assets panel's menu.

Figure 24.11. The Update Pages dialog box is used to update both Library items and templates used in the site.


Caution

When editing Library items, you can't use Cascading Style Sheets (CSS) or timelines. These features insert code into the head section of the page. Library items can insert a consecutive block of code into only the body of the document.


Note

You can't include style rules in a Library item; however, you can include class attributes. When a Library item is inserted, it assumes the styles set for that class in the attached internal or external style sheet, thus assuming the appearance of the rest of the site. Be sure, however, that the style sheet is attached or referenced, or the Library item cannot take on the correct styles.


When a Library item is updated, all markup between the comment tags is modified to reflect the changes. In templates, certain regions can be locked so you don't inadvertently modify pieces of the template.

Library items, however, have no such constraints. Changing the content of the inserted Library item doesn't break the link to the Library. However, if you manually modify the content of the Library item within the documentfor example, adding content to a table that was inserted as a Library itemthose changes are lost if and when the Library item is updated. If you don't want your changes to be overridden, you need to detach the inserted Library item from the source, as described in the following section.

Detaching from the Original

If you have an instance of a Library item that you don't want to be updated when the original item is updated, you can detach it from the original and preserve it in its current state. To detach an instance of a Library item from the Library, you need to break the link between the document and the item by selecting the instance of the item and clicking the Detach from Original button in the Property inspector (see Figure 24.12).

Figure 24.12. When the Library item is detached, the reference code that pointed to the Library item is removed from the page and the actual page code is inserted.


Before Dreamweaver detaches the item, a confirmation dialog box informs you that any future updates to the Library item won't be reflected in this instance (see Figure 24.13). If you Click the OK button, the item is detached and the corresponding markup removed in the code.

Figure 24.13. This dialog box confirms that you understand that after this instance is detached, it cannot be updated when the original Library item is edited.


Deleting Library Items

Deleting Library items is even easier than creating them. To delete a Library item, select the Library item to be deleted and click the Delete button at the bottom of the Assets panel. Although the item is deleted from the Library, the instances of the item in your site are not removed. Instead, they are detached from the original and remain intact in your web pages.

Caution

The delete process is irreversible. After a Library item is deleted, it is removed from the hard drive. Even though the original image that was used as a basis for the Library item may remain within the site and can still be referenced in your pages, the specific Library code that Dreamweaver created to reference the Library object is deleted.


Behaviors in Library Items

When you create a Library item out of content that contains Dreamweaver behaviors, the elements and event handlers are copied, but the associated JavaScript is not. Remember: The Library item can't update content that resides in the HTML head tag.

Fortunately, though, when you insert a Library item into a document, Dreamweaver is smart enough to know to add the appropriate JavaScript functions. If those functions are already in the head, Dreamweaver knows not to duplicate them.

Tip

Library items can be copied to another site in the same manner as any other asset on the Assets panel. Select the Library item (Command-click) [right-click] and select Copy to Site from the context menu. A pop-out menu lists all the defined sites to which you can copy the Library item. If this is the first Library item being added to the other site, Dreamweaver creates a Library folder in the local site.




Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net