Documentation Center

Creating a C# fragment Template Building Block

You can create C# fragments, for executing simple operations on a package, by entering C# code directly into the Source tab of a Template Building Block in the Content Manager Explorer.

Procedure

  1. Write a C# code fragment.
  2. Open the Content Manager Explorer.
  3. In a Folder, select New > Template Building Block.
  4. In the Source tab, in the Template Type drop-down menu choose C# Code Fragment.
  5. Copy and paste your C# code fragment into the source body.
  6. Save and close the Template Building Block.

Results

When you add this fragment to a Template Building Block, SDL Tridion Sites inserts the code fragment in its predefined method of a predefined class. When you incorporate the Template Building Block in a Component Template or Page Template, and run the Template against a Component or a Page, it executes the code in the code fragment.

What to do next

SDL Tridion Sites offers basic debugging functionality by attempting to compile the C# fragment in context when you save the Template Building Block.