Dreamweaver Get eXtension (DGX)
This Dreamweaver Function Source compensates for the perceived limitations of the out-of-the-box Dreamweaver Mediator.
The launch of Tridion Modular Templates in 5.3 completely revolutionized the way we develop templates, and we have now more power than ever before. However, mostly for those of us that were used to writing VBScript templates, there were also some functionalities that were perceived as missing from the Dreamweaver Template language, namely:
- Ability to format dates;
- Reading data from items that are not in the package;
- The ability to follow a component link chain, for instance, to retrieve the ALT tag for an image from its metadata fields.
Enter the DGX:
With this Dreamweaver Extension we expose functionality to the Dreamweaver mediator that was previously not possible. Using this extension you will be able to:
- Read from a component's parent folder;
- Read fields from a linked component;
- Read from a Page's parent Structure Group.
All this while using a standard Dreamweaver Notation for your fields Folder.Metadata.FieldName or Publication.Metadata.ComponentLink.Fields.FieldName.
This extension exposes 3 methods:
- GetFromItem(ItemID, FieldPath)
- GetDate(FieldPath, DateFormat, CultureInfo)
Using this extension
The following are examples of how you can use this extension in your Dreamweaver templates:
<img src="@@Get("Fields.Image")@@" alt="@@Get("Fields.Image.Metadata.AltTagField")@@"/>
More complex use case: reading component linked field values while iterating through a multi-value component link field:
<!-- TemplateBeginRepeat name="Link" -->
<!-- TemplateEndRepeat -->
This method can be used in special cases, like trying to read data from a component within a Page Template. The following code will read a value from component presentations in a page.
<!-- TemplateBeginRepeat name="Components" -->
<!-- TemplateBeginIf cond="Components.Schema.Title='Promo'" -->
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
Pass the SiteCulture parameter as a string, or (String) Package Item. See here for a list of valid Cultures: http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx (use the Culture Name column).
<div>@@GetDate("Fields.Date", "MMM d, yyyy", SiteCulture)@@</div>
The output of Get and GetFromItem can be tweaked by using special flags. A flag is turned "on" by pushing an item to the package with the following names:
By default, content is not HTML-encoded when retrieved using Get. By setting this flag, all content stored in TextFields, Item Titles, etc will be properly escaped (& becomes & < becomes <, etc)
If this flag is set, all (component field) output from Get will be wrapped with SiteEdit 1.3 style tags. This will enable inline-editing for SiteEdit 1.3 and you will not need to use the default SiteEdit building block in your component templates.
If this flag is set all (component field) output from Get will be wrapped with -tcdl:ComponentField- tags. This will enable inline editing for SiteEdit 2009 and you will have to add the SiteEdit 2009 Enable Inline Editing TBB to your Component Templates in order to enable field editing.
Differences from default DW Behavior
There are some use cases where the difference between this extension and the standard Dreamweaver mediator are obvious, like reading data from a component not currently in the package, or Folder metadata. Other use cases have more subtle differences:
- Text fields are not escaped by default.
If you have an ampersand in a text field, '&', the Dreamweaver mediator will escape it to & - Get will not do this unless you use the EscapeOutput flag.
- Multimedia Component Links in Rich Text Field
- If you link to a Multimedia component from a Rich Text field (not an image) the Dreamweaver Mediator will create a dynamic link to this binary and will not publish the binary itself. This means that you must manually or through some other means make sure the binary is published to the delivery server.
- If you use Get to read a Rich Text Field (@@Get("Fields.RichText")@@) this extension will ensure that:
- The Multimedia file gets published
- The link gets converted from a dynamic link to a "AddBinary"-style link
Installing this extension
To enable this extension you will need to:
- Add the "Tridion.ContentManager.Templating.Extensions.dll" file to your Content Managers GAC (Global Assembly Cache)
- Register it with the Tridion Template Engine by adding it to the file [Tridion]\Config\Tridion.ContentManager.Config
Adding it to the Global Assembly Cache
You can add the assembly to the Assembly Cache by executing:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil.exe /i Tridion.ContentManager.Extensions.Templating.dll
(You can also open [Windows]\Assembly in Windows Explorer and drag-and-drop the file into this folder).
Registering the Extension with the Tridion Template Engine
Edit the file [Tridion]\Config\Tridion.ContentManager.Config.
Towards the end of this file you will find a section named function Sources. Add the highlighted line below to your configuration file:
Make sure that this file is still well-formed after you edit it.
You will have to restart the Tridion Content Manager COM+ server, the Tridion Publisher and the Tridion Template Builder before you can use this extension.
This extension is created for version R5.3 but is valid, working and tested on SDL Tridion 2009 and 2011.