Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Inline Editing for .Net Template Building Block in SDL Tridion 2011 Sp1

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

My component Source looks like this.

<Content>
  <single>ABCD</single>
</Content>

I tried some thing like this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tridion.ContentManager.Templating.Assembly;
using Tridion.ContentManager.Templating;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.ContentManagement.Fields;
using System.IO;
using System.Collections;
using System.Xml;
using System.Xml.Linq;

namespace ClassLibrary1
{
    public class SampleTemplate : ITemplate
    {

        /// <summary>
        /// Transform as defined by ITemplate.
        /// </summary>
        /// <param name="engine">Templating engine</param>
        /// <param name="package">Package to process</param>
        public void Transform(Engine engine, Package package)
        {
            using (MemoryStream mem= new MemoryStream() )
            {
                Component component = engine.GetObject(package.GetValue("Component.ID")) as Component;
                ItemFields content = new ItemFields(component.Content, component.Schema);


                XhtmlField temp = (XhtmlField)content["single"];

                int i=0;
                XmlDocument xdoc = new XmlDocument();

                XmlElement root = xdoc.CreateElement("body");

                XElement xe = null;

                foreach (string val in temp.Values)
                {
                    string j=i.ToString();

                    XmlNode xnode = xdoc.CreateNode(XmlNodeType.Element, @"tcdl:ComponentField", "tcdlNamespace");
                    XmlAttribute name = xdoc.CreateAttribute("name");
                    XmlAttribute index = xdoc.CreateAttribute("index");
                    name.Value="single"+"["+i+"]";
                    index.Value = "0";
                    xnode.Attributes.Append(name);
                    xnode.Attributes.Append(index);
                    root.AppendChild(xnode);
                    i++;
                }
                package.PushItem("Output", package.CreateHtmlItem(xdoc.InnerText));
            }

        }
    }
}

Here "single" is Multivalued field.

I am getting blank output.

Can any one help how it can be done.

Thanks.

like image 313
Patan Avatar asked Dec 06 '25 09:12

Patan


1 Answers

Instead of:

package.PushItem("Output", package.CreateHtmlItem(xdoc.InnerText));

use

package.PushItem("Output", package.CreateHtmlItem(root.OuterXml));

Also, I noticed that you are not using field value anywhere. You are iterating over it, but value is not added into the output, not sure if that's what you want

like image 81
Andrey Marchuk Avatar answered Dec 09 '25 05:12

Andrey Marchuk