Wednesday, May 30, 2012

Adding Parameter Schemas in the .NET TBB Code

For those of you who don't know, a parameter schema is a special type of schema which allow developers to pass parameters to the Template Building Blocks (TBBs). The main purpose (if not the only) of this type of schemas is to make TBBs more flexible so that these can be reused across multiple environments and implementations.


Sometimes after setting the parameter schema in the TBB, somehow it seems to disappear after uploading a newer version of the assembly or after using Content Porter to import the TBBs. 


The parameter schema can be set programatically inside the TBB itself, the way to do this is simply by adding an attribute to the class as follows: 

[TcmTemplateTitle("Add page properties")]    [TcmTemplateParameterSchema("/webdav/02D%20_Design%20Parent/Building%20Blocks/System/Schemas/Parameters%20Schemas/Publish%20files%20Parameter%20Schema.xsd")]

    public class AddPageProperties : ITemplate
        public void Transform(Engine engine, Package package)
            // The place for the wizard to do the magic :)

The only thing you need to add is the attribute TcmTemplateParameterSchema to the class.