Getting the values ​​of a related component in Dreamweaver TBB and creating its SiteEditable

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

I do not know how to handle link components in TBB Dreamweaver.

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

The Source component is as follows:

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

Source of component B:

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

I want to write a DWT TBB that can access the fields of the associated component B from component A.

I want to use the RenderComponentField method.

Do I need to add any extensions to it, can I apply SiteEdit to it.

Share your views on him.

Thanks.

+6
source share
4 answers

There are two separate questions in this section:

  • How to access related component fields in DWT?
  • How to make fields from a related component editable in SiteEdit 2009?

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

In Tridion, by default, expression processing in DWT templates has only access to the Component fields that are in the package. Therefore, if you want to access the fields of component B, you will need to write C # TBB, which pushes this component into the package.

Example C # snippet:

 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 the TBB of a C # fragment and move it to CT before the DWT, you can do this in your DWT:

 @@ ComponentB.Fields.first@ @ 

Alternatively, you can use Nuno Dreamweaver Get eXtension (DGX) to access these fields without a TBB record:

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

The only downside to using DGX is that you will need to install it on every Tridion server. After that, a bunch of advanced functionality will be available in your DWT.

+6
source

The permitted fields of the associated component for editing are available in SiteEdit 2009 SP2. The SiteEdit interface is based on the SiteEdit command language , which is embedded in the HTML that it returns from the staging server.

So, let's say you have one component:

 <div class="cp"> <!-- Start SiteEdit Component Presentation: {"ID" : "cp_1", "ComponentID" : "tcm:12-549", "ComponentTemplateID" : "tcm:12-568-32", "ComponentVersion" : 5, "IsQueryBased" : false } --> <label>Title: </label> <span> <!-- Start SiteEdit Component Field: {"ID": "cf_1", "XPath": "tcm:Content/custom:Content/custom:Title", "IsMultiValued":false} --> Tips for getting insurance when you have a pre-existing condition </span> </div> 

Those Start SiteEdit comments contain the commands that your HTML gives to SiteEdit, and you can see how they mark the Component view and the header field.

If you create fields for a related component, you also need to have the corresponding Component Presentation command, for example:

 <div class="cp"> <!-- Start SiteEdit Component Presentation: {"ID" : "cp_1", "ComponentID": "tcm:12-54", "ComponentTemplateID": "tcm:12-56-32", "ComponentVersion" : 5, "IsQueryBased" : false } --> <label>Title: </label> <span> <!-- Start SiteEdit Component Field: {"ID": "cf_1", "XPath": "tcm:Content/custom:Content/custom:Title", "IsMultiValued":false} --> Tips for getting insurance when you have a pre-existing condition </span> <br /> <div class="cp"> <!-- Start SiteEdit Component Presentation: {"ID" : "cp_2", "ComponentID": "tcm:12-85", "ComponentTemplateID": "tcm:12-60-32", "ComponentVersion" : 2, "IsQueryBased" : true } --> <label>Byline: </label> <span> <!-- Start SiteEdit Component Field: {"ID": "cf_2", "XPath": "tcm:Metadata/custom:Metadata/custom:ByLine", "IsMultiValued":false} --> "It a huge problem, because ..." says one expert. </span> <br /> <label>Copyright: </label> <span> <!-- Start SiteEdit Component Field: {"ID": "cf_3", "XPath": "tcm:Metadata/custom:Metadata/custom:Copyright", "IsMultiValued":false} --> Getty Images </span> </div> </div> 

There are now two Start SiteEdit Component Presentation commands, one for the external component and one for the associated component. It is important to note here that the IsQueryBased property of the nested component view must be set to true. This tells the SiteEdit interface that the component view should not be present on the XML page that it retrieves from Tridion.

In the front-end, SiteEdit doesn't matter how the commands fit in the HTML.

Most often, people call RenderComponentPresentation and RenderComponentField , which mark the relevant parts. But, unfortunately, the RenderComponentField function can only be used to render fields from the so-called "context component", which looks like this:

 Item component = _package.GetByType(ContentType.Component); 

This means that in a single DWT, all RenderComponentField calls will work in the same Component context. Therefore, you can never call a RenderComponentField in one DWT to display fields from two different Components.

You have two options for solving this problem:

  • Call RenderComponentPresentation for a related component
  • Run the Start SiteEdit Component Presentation and Start SiteEdit Component Field yourself in DWT

Option 1 is the cleanest separation you can get: since you are visualizing fields from another component, you are essentially representing a different representation of the components. If you split the layout of related fields into a separate DWT and build a CT around this, you can do it the same way in your main DWT:

 @@RenderComponentPresentation(Component.Fields.Name, "tcm:1-2-32")@@ 

Walter explained this best in his article on Tridion patterns :

Since the scope of this Dreamweaver template is limited to displaying the current fields of the component, an additional step is required using the RenderComponentPresentation function. We need to pass the TCM URI of the multimedia component of this function along with the TCM URI of another Dreamweaver template.

Although this leads to more CTs and DWTs, these DWTs will be much simpler because you can now use the RenderComponentField in them as usual.

Option 2 really just means that you output HTML comments using the SiteEdit commands in your DWT. Since the command language is documented as part of the API (see Link above), there is little chance that it will change in future versions of SiteEdit 2009.

Sorry for the long story, you accidentally caused a difficult use case here. Hope this makes sense.

+5
source

If you use SiteEdit 2009, this is probably a bit more complicated than with the main component fields. SiteEdit works by wrapping content fields with JSON markup. There is no reason why you cannot determine if the purpose of the publication is phased, and write this JSON yourself.

Alternatively, Price has developed some template building blocks to help with SiteEdit, which are available here .

They are accompanied by a guide here , in particular, the embedded components section will be useful to you.

+2
source

You cannot read fields from B using standard Dreamweaver templates. You will need to write C # TBB to extract the related component and put it in the package as the Component type. You can then use the DWT syntax to read the fields of this component. For example: @@ linkedComponent.Fields.first @@

Siteedit is problematic in this, and different versions use different syntaxes and features. I am afraid that with the latest version you cannot edit such fields ...

-2
source

Source: https://habr.com/ru/post/913768/


All Articles