+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

5 Things: Benefits of External Widget Templates

by Josh Morales

Now that we've gone over Mapping External Templates for Sitefinity 4 Widgets, I thought it would be helpful to briefly review some of the benefits that are gained by using them in a new post in the 5 Things series.

1. Intellisense

The widget template editor within Sitefinity is a great for making quick edits to existing layouts and keeping all development inside one "box". However, if you're like me, you rely on Intellisense to keep the guesswork out of setting properties, and especially for writing code.

By developing your templates inside of Visual Studio, you gain the benefits of its rich Intellisense and code-completion, not to mention syntax and type checking and all the tools that come with the IDE.

2. Code-Behind

As we discovered in the previous article Running Server-Side Code in Sitefinity Widget Templates , it is possible to write code inside the Sitefinity Template Editor. And again, for quick snippets or simple tasks it's probably best to just inject it right into the template. However, for more complex scenarios, it's usually better to separate this code into the code behind file.

This is especially true if you need to make use of multiple functions and handlers in your code. Using a code-behind file helps keep your project organized.

3. Source Control

Internal Sitefinity widget templates are stored within the database. If your project is under source control, these templates cannot be versioned. By using external templates, you instead have physical files which you can version along with the rest of your code.

4. Edit and Refresh

Since external templates exist outside the Sitefinity Administration, it's possible to make changes to them without having to login to the backend of your website. In addition, since they are not compiled into your web application, changes can be realized with a simple refresh of the page, rather than having to recompile the entire solution.

5. Swap Templates on the Fly

Because templates are mapping to a specific path, swapping out one template for another is trivial. You just need to make sure the active template has the name that matches the path set by in the widget properties.

For example, say you have a folder with four templates for events, one for each season. The active template for summer would have the name EventsListTemplate.ascx, while the others might be named something like EventsListTemplate_spring.ascx, EventsListTemplate_fall.ascx, and EventsListTemplate_winter.ascx.

When fall rolls around, rename the active template to EventsListTemplate_summer.ascx and rename the fall template to EventsListTemplate.ascx to make it the active template for the control.

The possibilities are further expanded by using the Virtual Path Provider described in the previous post. You can hook up templates and swap them on the fly as long as they match the Guid for the template.

Your Thoughts

I hope these recent articles on External Templates have helped give you ideas on how you can enhance your Sitefinity projects. If you've discovered a new benefit or trick for using external templates, share your feedback via our Sitefinity 4 Discussion forum.

Leave a comment