Dreamweaver Syntax with FieldPath

Sometimes I get carried away with a TridionWorld forum post and come up with a really big example. So in the name of re-use (and not just as a euphemism for "copy and paste!"), here's a post on an example DWT.
The main take-away for me is that "FieldPath" is a nifty little variable that knows it's current context. Use it with deeply nested Dreamweaver template (DWT) loops to keep track of where you are in relation to an XML (component) source. A background with XSLT development is helpful, but not required. I'll have to follow up with exactly what Dreamweaver syntax means to a SDL Tridion implementation, but for now I'll leave it up to Walter, aka "the Tridion Architect" to explain the levels of Compound Templating.
Either syntax "@@" or "${}" works, but it's best to stay consistent within an implementation, team, or at least a template building block (TBB).

Note the shortcut" paths, but it might be a better practice to loop over the full paths with "Component.Fields" then "Field.Values") DWT TBB
<!-- TemplateBeginRepeat name="Fields" --><!-- for each of the fields under the root node of ${FieldPath} -->
 <!-- Fields is at index: ${TemplateRepeatIndex} (only one node) -->
 <!-- TemplateBeginRepeat name="Values" --><!-- for each of the values under the current path of ${FieldPath} -->
 <!-- Values is at index: ${TemplateRepeatIndex} -->
  LinkSource: ${RenderComponentField(FieldPath + ".LinkSource", 0)}
  LinkName:   ${RenderComponentField(FieldPath + ".LinkName", 0)}
  LinkTitle:     ${RenderComponentField(FieldPath + ".LinkTitle",0)}
  <a href="${RenderComponentField(FieldPath + ".LinkSource", 0)}
  " title="${RenderComponentField(FieldPath + ".LinkTitle",0)}
  ">${RenderComponentField(FieldPath + ".LinkName", 0)}
<!-- TemplateEndRepeat -->


(notice the goof on my embeddable schema namespace -- it shouldn't be plural IMO.
"FirstLine" node, the embedded schema root node could probably be "abstracted" to something like "link" but I'm being picky but any resident "architect astronauts" may appreciate it)
  <Content xmlns="http://createandbreak.net/schema/listoflinks">
    <LinkSource xlink:type="simple" xlink:href="tcm:7-149" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="filter test"/>
    <LinkTitle>Filter Example</LinkTitle>
    <LinkSource xlink:type="simple" xlink:href="tcm:7-65" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="First Component"/>
    <LinkTitle>First Link</LinkTitle>
    <LinkSource xlink:type="simple" xlink:href="tcm:7-69" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="Second Component"/>
    <LinkTitle>Second Link</LinkTitle>
    <LinkName>Another Link</LinkName>

Results in TemplateBuilder

(markup actually came out left-aligned, it's reformatted for clarity)
 <!-- for each of the fields under the root node of Links -->
 <!-- Fields is at index: 0 (only one node) -->
 <!-- for each of the values under the current path of Links[0] -->
 <!-- Values is at index: 0 -->
 LinkSource: tcm:7-149
 LinkName:   Filters
 LinkTitle:     Filter Example
  <a href="tcm:7-149" title="Filter Example">Filters</a>
 <!-- for each of the values under the current path of Links[1] -->
 <!-- Values is at index: 1 -->
 LinkSource: tcm:7-65
 LinkName:   Link
 LinkTitle:     First Link
  <a href="tcm:7-65" title="First Link">Link</a>

 <!-- for each of the values under the current path of Links[2] -->
 <!-- Values is at index: 2 -->
 LinkSource: tcm:7-69
 LinkName:   Another Link
 LinkTitle:     Second Link
  <a href="tcm:7-69" title="Second Link">Another Link</a>

Tips on DWT work:
  • Loops. Lots of Loops. It's familiar in an XSLT sort-of-way, though I still struggle with recursion. :-( - Just like hacking with XML, I like to use @@FieldPath@@ as a useful "print" function. We can keep the DWT open while working through changes and quick tweaks.
  • Just like XSLT, context is very important, Fields, Values, and FieldPath are your friend.
  • The breakdown in the default DWT is awesome and includes everything from how to use "mod" to stripe markup to checking each type of field. Definitely a "must read" as a companion to, or even before the documentation (mostly because it works).
In case I don't get around to it in a "Top 10 from 2011" or a "2012 Predictions" post, Happy New Year! That went quick! 

No comments:

Post a Comment

Feel free to share your thoughts below.

Some HTML allowed including links such as: <a href="link">link text</a>.