2

I'm using the code below to loop through CTs. I want to get the XML in the source tab. I can see it in the node if I look at the full XML block for the CT, but how can I get it from the ComponentTemplateData object? Do I need to call GetListXML instead?

var ro = new ReadOptions();
String[] pubs = new String[]{"tcm:0-1-1"};
foreach(String s in pubs){  
var pub = Tridion.Read(s, ro);
//Component Templates
filter.ItemTypes = new ItemType[]{ItemType.ComponentTemplate};
var list = Tridion.GetList(s, filter);

foreach(var item in list){
    ctb=(ComponentTemplateData)item;

    Debug.WriteLine(ctb.Title);
}

1 Answer 1

4

You can use componenttemplatedataobject.Content to get the xml as in the source tab. In your example if you use ctb.Content it will give you the xml as in the source tab

5
  • 1
    The Content property is already a string, so no need for a .ToString() on it Jul 23, 2015 at 7:56
  • 1
    Not sure if Content comes prepopulated from a GetList() call; you might need ctb = (ComponentTemplateData)Tridion.Read(ctb.Id, ro) Jul 23, 2015 at 11:31
  • @DavidForster removed it Jul 23, 2015 at 11:39
  • @BjørnvanDommelen Correct. The content won't be loaded from the GetList call's IdentifiableObjects Jul 23, 2015 at 11:57
  • Thanks! That worked. So GetList() returns IdentifiableObjects, which just contains some basic descriptive info and read returns the specific object.
    – Mr Smith
    Jul 23, 2015 at 13:16

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.