Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

tridion - Retrieving values of a linked component in Dreamweaver TBB - and making it SiteEditable

I am working on Dreamweaver TBBs in SDL Tridion 2011 SP1.

I am unaware of handling component links in Dreamweaver TBBs.

Consider my Component name is "A" which has link to another component "B".

Component A source looks like this:

<Content xmlns="Some UUID">
    <Name xlink:type="simple" xlink:href="tcm:184-1897" 
          xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="B"></Name>
</Content>

Component B source is:

<Content xmlns="Some other UUID">
    <first>first field</first>
    <second>second field</second>
</Content>

I want to write a DWT TBB which can access the fields in the linked component B from Component A.

I want to use RenderComponentField rendition method.

Do I need to add any extentions to it, will I be able apply SiteEdit on it.

Please share your views on it.

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are two separate questions in this topic:

  1. How to access fields from a linked Component in DWT?
  2. How to make fields from a linked Component editable in SiteEdit 2009?

This is the answer to question 1. I will provide a separate answer for question 2.

In Tridion's default handling of expressions in DWT templates you only have access to fields of Components that are in the package. So if you want to access the fields of Component B, you will have to write a C# TBB that pushes that Component into the Package.

A sample C# fragment:

var componentA = (Component) engine.GetObject(package.GetValue("Component.ID"));
var fieldsA = new ItemFields(componentA.Content, componentA.Schema);
var linkField = (ComponentLinkField) fieldsA["Name"];
var componentB = linkField.Value;
var itemB = package.CreateTridionItem(ContentType.Component, componentB);
package.PushItem("ComponentB", itemB);

If you put this in a C# fragment TBB and drop it into your CT before the DWT, you can do this in your DWT:

@@ComponentB.Fields.first@@

Alternatively you can use Nuno's Dreamweaver Get eXtension (DGX) to access such fields without writing a TBB:

@@Get("Fields.Name.first")@@"/>

The only downside to using the DGX is that you will need to install it on every Tridion server. After that, a heap of extended functionality is available in your DWTs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...