Add ITemplate content to a controls markup

When building web controls, a common scenario is how to cascade control parameters to the control from the markup (or code-behind). Within Sitecore controls this is typically the Field you want to render.

This approach to programming controls works very well until the set of parameters becomes very long or the control doesnt need to know about each parameter. Consider embedding a flash movie, the number of parameters to code could be huge.

In the flash example, often the parameters aren’t needed by your c# code, instead they just to be rendered to the markup.

One useful tip is that you can get information from your code behind into the template markup eg

To build the control you need to add the following attribute:

And then the template you want to use:

The content of the template can be extracted as a string with the following:

Note, based on the chosen implementation, you may not need the content of the template as a string. Instead you could simply instantiate to the control’s child controls

One thought on “Add ITemplate content to a controls markup

Leave a Reply

Your email address will not be published.