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

前端 未结 4 1366
孤城傲影
孤城傲影 2020-12-18 05:10

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\"

4条回答
  •  猫巷女王i
    2020-12-18 05:30

    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.

提交回复
热议问题