-1

How to access componentlink field names in third level? I have a schema which contains a field as embeddable schema, in that embeddable schema, I have a component link which is derived from another schema. How can i retrieve the field of that schema?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

4 Answers4

7

It really depends on the purpose of those field(s), perhaps you could provide some more information?

Another option not mentioned here is to write your own C# building block to add these 3rd level components to your package. By doing so you make it a lot simpler to work with them in your DWT layout.

For example if your third-level items are used to generate a list of office locations, you could write a C# block to obtain all the relevant office location components and add them to your package as a component list 'Locations' all you would simply need to do in your DWT is loop those items and provide the display you need.

Personally I don't like to use / add functions into DWT, I try to keep it as simple as possible, again if you can provide more information about your scenario that would generate a better answer for you from the community.

johnwinter
  • 3,624
  • 15
  • 24
6

As far as I know, you need a special DWT TBB to get some control over your embedded/componentlinks. Maybe you could use Nuno's Get Extensions ? http://www.sdltridionworld.com/community/extension_overview/dreamweaver_get_extension.aspx Or use Razor Mediator, perhaps: http://www.sdltridionworld.com/community/2011_extensions/razormediator.aspx

MDa
  • 579
  • 2
  • 10
5

To prevent having to use either the DGX (as MDa suggests) or write a C# TBB (as John Winter suggests), you can also simply call RenderComponentPresentation to render the linked Component with the template that you want to use.

<!-- TemplateBeginRepeat name="Component.Fields.LinkFieldName" -->
    @@RenderComponentPresentation(Field, "tcm:1-23-32")@@
<!-- TemplateEndRepeat -->

Where tcm:1-23-32 it the TCM URI of a Component Template that simply renders the name of the Component as a hyperlink. Inside the DWT that you use in tcm:1-23-32 you can then simply refer to all fields and properties of the linked Component like Component.Title, Component.Fields.Field1, etc.

Note that the relevant topics have been covered already in these other questions/answers:

If somehow these did not help you enough, I suggest you post the XML of your Component and the DWT that you're trying to make work.

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
4

Here a quick sample using C#

Session session = engine.GetSession();
Item componentItem = package.GetByName(Package.ComponentName);
Component component = new Component(new TcmUri(componentItem.GetValue("ID")), session);

ItemFields itemFields = new ItemFields(component.Content, component.Schema);
IEnumerable<ComponentLinkField> ie = itemFields.OfType<EmbeddedSchemaField>().OfType<ComponentLinkField>();
for (IEnumerator<ComponentLinkField> e = ie.GetEnumerator(); e.MoveNext(); ) {
    Component linkedComponent = e.Current.Value;
}

By using Linq you can navigate through the fields structure really quick and get results. It will give you the Component Links in the third level, of course you can use the same to go deeper in the structure.

Eric Huiza
  • 393
  • 1
  • 4