How to add user-defined methods in C # TBB (C # code snippet)?

I am creating C # TBB (C # code snippet). To do this, I need to write a userdefined method. I tried to create it using <%! %>. How to access a user-defined method in code. Thanks in advance. Please suggest me a way to solve this problem.

+7
source share
3 answers

The reference to the TOM.NET API is given in 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 a namespace enclosed between quotation marks in a piece of code. Any class that you import must be present in the global assembly cache.

 <%! ... %> 

Declares methods, constants, and classes for the rest of the code snippet. Ads cannot contain the string "%>". Please note that any classes you create can only reference a piece of code.

 <%RunTemplate Template="tcm:1-184-2048" Class="Tridion.Templating.Examples.ExampleTemplateClass"%> 

Starts a special unit for building a .NET assembly template, identified by the URI in the Template attribute. This statement is typically generated by the Tridion 2009 SDL itself when loading the .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 non-standard .NET assembly, which must be present in the global assembly cache. Use the fully qualified name of the assembly.

+11
source

Here is the link link link with an example pointing Nickol.

+3
source

Check out the links below for complete information on creating functions as well as classes in a C # code snippet.

Classes are defined inside a C # code snippet using the construct: <%! %> <%! %> .

This USER specific class is placed as the NON-STANDARD CLASS PRELIMINARY CLASS created by Tridion when compiling a C # code snippet. Check out this blog post for details on compiling a C # code snippet and predefined classes, methods generated by tridion, along with an understanding of the Tridions relationship A predefined class with a user-defined class in a C # code snippet

As we said above, we need to understand that user classes in a C # code snippet cannot access predefined variables of the type: log, engine, and package, since these variables are actually declared Private in the predefined class generated during the collection.

[For complete information, including code examples, check the links above]

+1
source

All Articles