The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
In our Sample Contacts Pluggable Module we have demonstrated how you too can use embedded templates when building your pluggable modules. Before we dissect the approach, we should first consider the two biggest benefits that come with embedding templates:
Secondly, if you do not distribute the templates as external files, there is no danger that on the module update you will overwrite the modifications made by the developers that use your module.
All in all, you get all the benefits as a module developer, which Sitefinity team gained with this new feature. It is also important to note, that you can effortlessly take advantage of Sitefinity ControlsConfig file to map your embedded templates to external ones. The mapping is a built-in feature of ViewModeControl and SimpleControl base controls.
/// <summary> |
/// Gets or sets the path to a custom layout template for the control. |
/// </summary> |
/// <value></value> |
[WebSysTemplate(BlogCommentsEditView.BlogCommentsEditViewTemplateName, "BlogCommentsEdit_Desc", "/Blogs", false, "2009-01-30")] |
public override string LayoutTemplatePath |
{ |
get { return base.LayoutTemplatePath; } |
set { base.LayoutTemplatePath = value; } |
} |
/// <summary> |
/// Gets the name of the embedded layout template. This property must be overridden to provide the path (key) to an embedded resource file. |
/// </summary> |
/// <value></value> |
protected override string LayoutTemplateName |
{ |
get { return BlogCommentsEditView.BlogCommentsEditViewTemplateName; } |
} |
private const string BlogCommentsEditViewTemplateName = "Telerik.Blogs.Resources.ControlTemplates.Backend.CommentsEdit.ascx"; |
So, let us now examine the decision process of the ViewModeControl and UserControl when they decide how will they load the template:
<test:MyControl id="myControl1" runat="server"> |
<LayoutTemplate> |
This is my template. |
</LayoutTemplate> |
</test:MyControl> |
The given priorities ladder ensures for maximum flexibility.
WebSysTemplate attribute class needs to be implemented in every assembly that will use embedded templates. The implementation is always same and can be directly pasted from the following example:
/// <summary> |
/// This class defines the attribute for specifying embedded templates |
/// </summary> |
[AttributeUsage(AttributeTargets.Property)] |
internal class WebSysTemplate : EmbeddedTemplateAttribute |
{ |
public WebSysTemplate(string resourceName, string description |
, string defaultExtPaht, bool isFrontEnd, string lastModified) |
: base(resourceName, description, defaultExtPaht, isFrontEnd, lastModified) |
{ |
} |
/// <summary> |
/// Gets the description. |
/// </summary> |
/// <value>The description.</value> |
public override string Description |
{ |
get |
{ |
return Messages.ResourceManager.GetString(base.Description); |
} |
} |
/// <summary> |
/// When implemented in a derived class, gets a unique identifier for this <see cref="T:System.Attribute"/>. |
/// </summary> |
/// <value></value> |
/// <returns>An <see cref="T:System.Object"/> that is a unique identifier for the attribute.</returns> |
public override object TypeId |
{ |
get |
{ |
return typeof(EmbeddedTemplateAttribute); |
} |
} |
} |
Now, let us go back to the attribute and its meaning. In Sitefinity 3.6 this attribute does not serve any purpose, but it has been placed here so that your Views and controls can be ready for Sitefinity 4.0 which will feature Template management tool. Let us examine the sample attribute implementation once again:
[WebSysTemplate(BlogCommentsEditView.BlogCommentsEditViewTemplateName, "BlogCommentsEdit_Desc", "/Blogs", false, "2009-01-30")] |
All these information, will be used by our template manager tool to enable users to browse through template, export them and modify them.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.