3

I would like to pass the entirety of a Component's data to a user control from a Component Template. I'm thinking I would need to pass the XML.

I know how to pass individual field data:

<ucTestUC:TestUC ComponentFieldData="@Component.Fields.xxx" runat="server"/>

But am unsure how I would pass all of the component's data.

3 Answers 3

6

Achieving this can be quite simple or complicated. The easiest thing to do would be use an inner property on your user control so you get something like this:

<TestUC:TestUC runat="server">
    <ComponentXML>
        All the XML of your Component Fields and Metadata fields here...
    </ComponentXML>
</TestUC:TestUC>

You can then load the complete field set of XML on the server side as an XML document. Take a look here for examples on using Inner Properties. You could also make a much more complicated User Control which is aware of the Schema Structure, and generates a class from it.

All that said, if this is key to your architecture, and you are trying to expose all of you component fields on the Content Delivery side, please take a look at DD4T. It has existing classes for exposing all content on the Content Delivery Side

3

Can you explain a bit more on what you want to achieve ? There are a few possible options here.

I don't think it's a good idea to pass all of the component's fields as properties to a user control like that. It might cause issues with rich text fields.

What is usually done is to pass the tcm id of the component to the user control, and let the user control load all necessary data from the broker.

your template then just needs to write out

<ucTestUC:TestUC ComponentId="@Component.Id" .../>

Next to that, you could create a dynamic component presentation that outputs all relevant component data as xml, and stores this in the broker (check how DD4T (https://code.google.com/p/dynamic-delivery-4-tridion/) does that)

And finally, your user control could then query the broker for that specific component, get the data from the broker, and then use this data to render the user control.

Another option could be to add the components content and metadata xml to a template of the user control.

<ucTestUC:TestUc runat="server">
   <Content>--write all component's content fields here--</Content>
   <Metadata>--write all component's metadata fields here--</Metadata>
</ucTestUC:TestUc>

Then, it's up to the user control to read the contents of the template, and parse the content fields you need.

To find out more about templated user controls, check this link http://msdn.microsoft.com/en-us/library/36574bf6%28v=vs.140%29.aspx

1

Accessing all of the field data of a component can be done using

<!-- TemplateBeginRepeat name="Component.Fields" -->
<@@Field.Name@@>@@Field@@</@@Field.Name@@>
<!-- TemplateEndRepeat -->

You might want to have a look at the "Default Dreamweaver Component Design" TBB provided with the default templates on how to handle various field types (if you need to).

If you aren't required to use a DWT you can of course retrieve the full component XML from a C# fragment or assembly TBB by using the method ToXml() of the Component class:

Component component = engine.GetObject(tcmUri) as Component;
string xml = component.ToXml().OuterXml;
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Xml, xml));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.