Often, when you have database item (such as a product, article, or event), you will want to associate one or more files with it. These may be photos, documents, spreadsheets, or anything else.
Because different situations have different requirements, there are several different ways to associate files with database items. When you add a custom field to an item type, you'll see the following choices among the field types:
The last of these options, Legacy Related Assets, uses an older approach that we do not recommend for new designs. It provides a single pool of related files for an item type, and you cannot have more than one Legacy Related Assets field for a given item type.
When creating a custom item type, add a field and set the field type to Dedicated File.
The Dedicated File field type is intended for situations in which you want to associate a single file with the database item, which is "dedicated" to that item; that is, the file is only used in the context of the item.
There are no options for a dedicated file; the goal of this field type is to provide the simplest possible path for attaching a file to a database item. It has the following behaviors:
Accessing a dedicated file using WebvantaScript is simplicity itself. If you have named the field "logo", you can display the logo on a page as follows:
<img src="<w:logo />">
If the file is a PDF document, for example in a field named "data_sheet", then you'd simply link to it:
<a href="<w:data_sheet />">Data Sheet</a>
While each Dedicated File field references only a single file, you can have as many Dedicate File fields as you need in one item type. For example, you might have one for a logo, and another for a data sheet.
While the Dedicated File type provides the simplest admin experience and the easiest access from WebvantaScript, the Related Assets type is much more flexible.
When creating a custom item type, add a field and set the field type to Related Assets.
The admin user can then add files using various approaches when creating or editing a database item:
If you want to allow selection of multiple files after clicking the Add File button, enter an asterisk (*) in the Type Options field. Otherwise, only one file can be selected.
Note that multiple file selection only applies to files that are already on the server. When uploading from the user's computer, only a single file can be selected. To upload multiple files at once, combine them into a zip file and upload the zip file.
Suppose you have two Related Assets fields: documents and photos. When you are in an item context (such as on an item page inside a <w:kb:item> block, or in a <w:kb:item:each> loop), you can access them as follows:
<w:photos>
<w:assets:each>
<img src="<w:path />" />
</w:assets:each>
</w:photos>
<w:documents>
<w:assets:each>
<a href="<w:path />"><w:filename /></a>
</w:assets:each>
</w:documents>
For images, you can include a rendition name in the w:path statement if you want to access a size other than the original (see Creating and Accessing Image Renditions for details.
The Legacy Related Assets type is an older feature that is now deprecated. For new designs, use the Related Assets field type.
The Legacy Related Assets type operates much like the new Releated Assets field type, except that you don't need to set the name context and there can be only one pool of files for a given item type. (If you use multiple Legacy Related Assets fields, you will not be able to access the groups separately.>
When you are in an item context (such as on an item page inside a <w:kb:item> block, or in a <w:kb:item:each> loop), you can access the related assets (assuming they are images) as follows:
<w:assets:each> <img src="<w:path />" /> </w:assets:each>
Note that you can also define associations as part of the asset's metadata. For example, when you upload (or update) an asset (uploaded file of any type), you can assign it to one or more categories or tags. So you could, for example:
You can then access all of the chair photos whenever you are displaying a chair product page.
For more details on this approach, see Accessing Images and Other Files.