0

I need to debug the following block of code with the Template builder:

<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="Tridion.ContentManager.Publishing" %>
<%@ Assembly Name="Sanofi.Tridion.Templating.SystemConfiguration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=35c557fa23cf3f27"%>
<%@ Import Namespace="Sanofi.Tridion.Templating"%>

string pubUrlName = "PublicationURL";
string pubLangName = "PublicationLanguage";
string pubID = "PublicationID";
string outputName = "PublicationList";
string curretPubIndex = "CurrentPubIndex";
if (engine.RenderMode == RenderMode.Publish)
{
    PublicationTarget pubTarget = engine.PublishingContext.PublicationTarget;
    IList<Publication> list = new List<Publication>();
    IList<TcmUri> pubList = new List<TcmUri>();
    list = pubTarget.Publications;
    Publication currentPub = engine.GetSession().GetObject(string.IsNullOrEmpty(package.GetValue("Page.Publication.ID")) ? package.GetValue("Component.Publication.ID") : package.GetValue("Page.Publication.ID")) as Publication;
    string pubLanguage = "";
    string pubURL = "";
    int i = 0;
    foreach (Publication pub in list)
    {
        SystemConfigurationEngine sysCfg = new SystemConfigurationEngine(engine, package, log, pub);
        sysCfg.rootFolder = "/Building Blocks/System Configuration Entries";
        pubLanguage = sysCfg.GetValue("Publication.Language");

        if ( sysCfg.GetValue("Publication.Device").ToString().Equals("desktop"))
        {

            if (pub.Id != currentPub.Id)
            {
                pubURL = sysCfg.GetValue("Publication.URL");
                pubList.Add(pub.Id);
                package.PushItem(pubUrlName + i, package.CreateStringItem(ContentType.Text, pubURL));
                package.PushItem(pubLangName + i, package.CreateStringItem(ContentType.Text, pubLanguage));
                package.PushItem(pubID + i, package.CreateStringItem(ContentType.Text, pub.Id.ToString()));
                i++;
            }
            else
            {
                pubList.Add(pub.Id);
                package.PushItem(pubUrlName + i, package.CreateStringItem(ContentType.Text, ""));
                package.PushItem(pubLangName + i, package.CreateStringItem(ContentType.Text, pubLanguage));
                package.PushItem(pubID + i, package.CreateStringItem(ContentType.Text, pub.Id.ToString()));
                package.PushItem(curretPubIndex, package.CreateStringItem(ContentType.Text, i.ToString()));
                i++;        
            }
        }
    }
    package.PushItem(outputName, package.CreateComponentUriListItem(ContentType.ComponentArray, pubList));
    package.PushItem("PublicationCount", package.CreateStringItem(ContentType.Text, i.ToString()));

}

it seems i need a package to run it against but i don't know how i'm supposed to create this package.

Will the line

if (engine.RenderMode == RenderMode.Publish)

be a problem since i'm not in a publish context ?

Thanks in advance for your help.

2
  • Judging by the code, it looks like this is stored directly in a Template Building Block instead of part of an assembly. I don't think you can debug this, only code in an assembly/visual studio can be debugged.
    – Nuno Linhares
    Mar 29, 2016 at 16:35
  • And to make matters worse, a large part of the code only executes while publishing, so won't be hit while debugging in Template Builder. Mar 29, 2016 at 18:46

1 Answer 1

0

The code probably wouldn't work if you don't have the line:

if (engine.RenderMode == RenderMode.Publish)

because it would raise an error when trying to extract Publication Target when you run it in Template Builder.

From the code as I can see this particular C# Fragment needs to be a part of a Page Template. For you to debug this I would suggest creating a Page Template and adding this C# Fragment and one DWT file. In the DWT file you can only render the packages created by the C# fragment. ( @@PublicationCount@@ and @@PublicationList@@) When you publish the particular page created for this Page Template as a result on Delivery side you would get the values of the packages in the C# fragment. This is the only way you can debug this code.

0

Your Answer

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