How to add user defined methods in C# TBB(C# code fragment)?
c#, tridion
Solution
The TOM.NET API reference provides the following example:
<%@ Import Namespace="Tridion.ContentManager.Publishing"%>
<%!
private string ExtraString()
{
return "Something added by the C# template";
}
%>
log.Debug("Executing C# template");
if (engine.RenderMode == RenderMode.Publish)
{
package.GetByName(Package.OutputName).AppendToStringValue(ExtraString());
}
In addition to the above, the following syntax is supported:
<%@Import Namespace="..." %>
Imports the namespace enclosed between the quotation marks into the code fragment. Any class you import must be present in the Global Assembly Cache.
<%! ... %>
Declares methods, constants and classes for the rest of the code fragment to use. The declarations cannot contain the string '%>'. Note that any classes you create can only be referenced within the code fragment.
<%RunTemplate Template="tcm:1-184-2048" Class="Tridion.Templating.Examples.ExampleTemplateClass"%>
Runs a specific .NET Assembly Template Building Block, identified by the URI in the Template attribute. This statement is typically generated by SDL Tridion 2009 itself when you upload a .NET assembly, to provide access to a specific class in the .NET Assembly.
<%@Assembly Name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>
Inserts a reference to a nonstandard .NET assembly, which must be present in the Global Assembly Cache. Use the full assembly name.
Problem
I am creating a C# TBB(C# Code fragment). For that I need to write a userdefined method. I tried creating it using <%! %>. How to access the user defined method in the code. Thanks in advance. Please suggest me a way to solve this issue.