This is going to be my first post on SDL Tridion and I’m going to explain different ways to reference a parameter schema from a ITemplate implementation using the TcmTemplateParameterSchema class attribute.

So, assuming you are creating a nice .NET assembly with your Template Building Blocks and you want to reference a schema, here’s how you could do:

Way #1: direct reference using the ID

1) In the CMS create a Parameters Schema and take the id ( something like “tcm:73-7323-8” )

2) add the class attribute to your ITemplate implementation, BUT change the id of the folder to 0:

[csharp]
[TcmTemplateParameterSchema("tcm:0-7323-8")]
public class PageRevisionDate : ITemplate {
……
}
[/csharp]

this is why the uploader is trying somehow to reference the schema in the same destination folder of the assembly first. If you don’t replace the 0, the upload will fail 🙂

Way #2:  embed the schema as a resource

I found this method on Rob Stevenson-Leggett’s blog, so I just link it. There’s also a repo on GitHub so go and take a look 😀

One thing I don’t like of Way #1 is that you’re hardcoding the id of the schema. Hardcoding’s a big no-no in big project so we need to find another way. Way #2 instead forces you to create the schema in the CMS, copy/paste the xsd in Visual Studio and update it each time you make some changes to the schema. I’m a lazy guy so I really want a better way. And here we get Way #3!

Way #3:  reference an existing schema using webdav url

Let’s start with the drawbacks first: the only real requirement with this approach is that you have to create the schema in the same folder where you’re uploading the assembly. This may be not an issue, depends on how you have architectured your project.

All you need to do is to create the schema as before (remember the directory thing), take it’s WebDAV url and use it as a parameter for the class attribute:

[csharp]
[TcmTemplateParameterSchema(@"/webdav/910 Design HTML/Building Blocks/System/Templates/Assemblies/Page Revision Date.xsd")]
public class PageRevisionDate : ITemplate {
……
}
[/csharp]

Here we go!