0

I want to make it generic method if we want to read the component template id based on the component template name for any publication or folders it should work.

Need to be done using C# and want to return the component template ID and the component template name

String[]  arrctNames = new String[[%=i%]];
int[]  arrctIds = new int[[%=i%]];

[%
   i = 0
  For Each Node In NodeList 
%]

   arrctNames[[%=i%]] = "[%=Node.getAttribute("Title")%]";

   arrctIds[[%=i%]] = [%=Mid(Node.getAttribute("ID"), I

nStr(Node.getAttribute("ID"),"-")  + 1,  Len(Node.getAttribute("ID")) -InStr(Node.getAttribute("ID") ,"-") - ( 1 + Len(Node.getAttribute("ID")) - InStr(InStr(Node.getAttribute("ID") ,"-")+1,Node.getAttribute("ID") ,"-")))%];

[%
     i = i + 1
     Next
     Set NodeList =Nothing
%]

   for(int i=0;i<arrctNames.length;i++)
   {
     //check if the ct name matches with the string
       //if(!(arrctNames[i].toUpperCase().indexOf(componentTemplateName.toUpperCase()) == -1))
       if(arrctNames[i].toUpperCase().equals(componentTemplateName.toUpperCase()))
       {
          return arrctIds[i];    
       }
   }
   return -1;
 }     

the above mentioned code is in java.

I want to do the same thing using the c# .

The current output rendered in this format:

 String[]  arrctNames = new String[125];
 int[]  arrctIds = new int[125];

 arrctNames[0] = "CT";
 arrctIds[0] = 1;

The similar way want to do in the C#.

For the conversion i have started i'm starting in the right way please suggest me

RepositoryItemsFilter filter = new RepositoryItemsFilter(_engine.GetSession());

filter.ItemTypes = new ItemType[] { ItemType.ComponentTemplate };

filter.Recursive = true;

Publication pub = this.GetPublication();

int i;

String[] arrctNames = new String[i];

int[] arrctIds = new int[i];

foreach (XmlNode node in pub.GetListItems(filter).ParentNode.ChildNodes)

{

    string ctId = node.Attributes["ID"].Value;

    string ctname = node.Attributes["Title"].Value;

}    
4
  • 1
    Welcome to the Tridion Stack Exchange. It would help if you could let us know what investigation that you have already done, and the problems that you came across. Also, where are you attempting to do this? Is it using the Core Service, within Templating, or elsewhere (Workflow, Event System, etc.) Sep 11, 2014 at 11:18
  • we are upgrading from tridion 2011 sp1 hr1 to tridion 2013 sp1. The current code about the getcomponenttemplate id is in java now want to write that getcomponent template id using C#.
    – Doors
    Sep 11, 2014 at 12:29
  • 2
    Hi Doors, in its current form your question is difficult to answer because it is too broad. Please edit the question with more detail such as what you tried to do to achieve this, any error messages you receive etc. Sep 11, 2014 at 13:32
  • Hi Doors. You might want to take a look at the GetListItems() method in the API docs and online documentation. That should give you a start. Sep 11, 2014 at 14:34

2 Answers 2

2

Seems you are populating the arrays that will be used in the front end (java) from the CMS using vbscript, as you are using the following syntax

arrctNames[[%=i%]] = "[%=Node.getAttribute("Title")%]";

This information will be used in the delivery as you need the relation between the template id and the template name available there.

So for me the question seems more how to replace vbscript syntax with C# syntax for calculate the name of the template based on the id of the template.

First thing you have to do is to move the current vbscript page template into a Compound Page Template and iterate throughout the Component Templates using C# for generate the array information.

The result you want to obtain is the same (populate arrays that will be used in the delivery) but those will be produced with C# instead with vbScript

2
  • oh now I think I get it, it is a VBScript Template and it is outputing Java code? Sep 11, 2014 at 14:28
  • I think that is the case Bart
    – Miguel
    Sep 11, 2014 at 14:29
2

I'll structure this as an answer, even though your question is vague and incomplete. Assuming Miguels assumption is correct, you actually want to rewrite VBScript Templates in C#...

I wouldn't suggest just rewriting those templates. The way I see it, you have old VBScript Templates generating Java code for your website (plain old JSPs I guess then). So you are using 10 year old technology on the Template side to generate 10 year old technology for your website. No need to change either one if that is what you want.

But changing the Templates to use Modular templating and C# assemblies, just to generate the same old JSPs again, that doesn't make sense. If you understand your template code is in need of a change (because its technology has long been deprecated), then you should also understand that the website code you were generating with them is also due for a change (JSPs were called dead in 2007 already -> https://weblogs.java.net/blog/zarar/archive/2007/04/are_jsps_dead.html).

There is a difference between upgrading and UPGRADING (sorry, I couldn't think of another word for it). If you just want to upgrade the CMS version, stick with the old template and website code. If you want to UPGRADE into current technology, look at what requirements the website has, choose an appropriate architecture, publishing model and web (application) framework and implement that. Don't rewrite templates, if you need to fix them, fix them, if you need a new implementation, create new ones.

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.