Documentation Center

C# fragment custom syntax

In your C# code fragment, you can make use of some custom scripting syntax.

If you are creating a C# code fragment, then by default, all content of your code fragment is inserted into a predefined method in a predefined class. SDL Tridion Sites offers you a number of preset variables to work with, and enables you to add methods to your code fragment. By marking these methods with special tags, you can ensure that those methods are added to the same class.

<%@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. If you want a certain namespace to be universally imported in all of your C# fragments, you can configure it in the Content Manager configuration file, Tridion.ContentManager.config instead.
<%! ... %>
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 Sites 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. If you want a certain assembly to be universally available in all of your C# fragments, you can configure it in the Content Manager configuration file, Tridion.ContentManager.config instead.