Showing posts with label templating. Show all posts
Showing posts with label templating. Show all posts

Monday, 22 October 2012

Get list of publications from Tridion sorted using Linq


Sometimes you need to get a list of child publications in to a dropdown etc, this is an extension to the code from http://stringwriter.com/tag/tridion/



//Call like this  GetChildPublications("tcm:0-5-1");     
private string GetChildPublications(string parentTCM)
    {
        TDSE tdse = new TDSE();
        tdse.Initialize();

        //gets current publication object
        Publication pub = tdse.GetPublication(parentTCM);
        //gets row filter object
        ListRowFilter filter = tdse.CreateListRowFilter();
        //filter only publication type
        filter.SetCondition("ItemType", 1);
        //returns using publications as xml

        string temp = "";

        XDocument xmlPublications = XDocument.Parse(pub.Info.GetListUsingItems(ListColumnFilter.XMLListIDAndTitle, filter));
        XmlNamespaceManager NS = new XmlNamespaceManager(new NameTable());
        NS.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");

        ListItem li;
        foreach (XElement PubNode in xmlPublications.XPathSelectElements("/tcm:ListUsingItems/tcm:Item", NS).OrderBy(s => (string)s.Attribute("Title")))
        {
            li = new ListItem();
            li.Text = PubNode.Attribute("Title").Value;
            li.Value = PubNode.Attribute("ID").Value;
            GlobalPublicationID.Items.Add(li);
        }

        return temp;
    }

Thursday, 22 March 2012

Tridion Loop through multiple embedded fields


Schema


Embeddable Schema

Field1 and Field2 both optional and multi value.



Component




Component Template
[%
For Each value in Component.Fields.Item("EmbeddedFields").Value
                For Each value2 in value.Item("Field1").Value
                                WriteOut "Field1: " & value2 & "<br>"
                Next
                For Each value2 in value.Item("Field2").Value
                                WriteOut "Field2: " & value2 & "<br>"
                Next
Next
%]


The outcome