Create a c# Template Building Block with the following code in it:
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
if (package.GetByName(Package.ComponentName) == null)
{
log.Debug("Not running in a Component Template, exiting.");
return;
}
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Xml, component.Content.OuterXml));
And use it in your template without any other building blocks.
This will output the exact content of Component.Content
, which is rarely what you really want (for instance, how do you deal with binaries or linked components?), so you'll want to evolve to something else, with more details, and possibly removing the namespace from the XML nodes too...
i typically use a large switch(field.GetType().Name)
and then deal with each field type as appropriate, something along these lines:
foreach (ItemField field in content)
{
string fieldType = field.GetType().Name;
switch (fieldType)
{
case "XhtmlField":
// do something, like write it to an XmlWriter
break;
And so on and so forth.