5 Things: Benefits of External Widget Templates

5 Things: Benefits of External Widget Templates

Posted on May 11, 2011 0 Comments

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.

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.

progress-logo

The Progress Team

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.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation