Codegarden US 2008 - Chicago, IL
Question: When should you use .NET User
Controls and when should you use XSLT when creating Umbraco
Macros?
In general, XSLT should be used when the macro is creating UI
(presentation) and .NET User Controls should be used when business
logic is being executed/required.
Technically there is nothing wrong with using .NET User Controls
to create presentation or XSLT to encapsulate business logic, but
Umbraco Best Practices indicate that XSLT is best for presentation
and .NET User Controls are best for business logic.
Also, "the Umbraco way" is to use XSLT for presentation, so this
convention is the recommended approach.
When the goal is to "put things back" into Umbraco (such as
data, members, nodes) then .NET User Controls are again the obvious
choice. XSLT is "one-way" as it can only pull data out.
Question: What about external data?
For RDMS-based data .NET User Controls are the obvious
choice. For URL or web service based data either is
appropriate. In some scenarios it makes sense to implement a
.NET web service to expose the data (or implement an XSLT Extension
via a .NET Class Library) and XSLT to retrieve and display it.
Question: Are there performance tradeoffs
with one approach or the other?
Not really. Of course, creating high performance code with
either approach is possible as is creating poor performing
code.
Question: What about developer
productivity?
Visual Studio can help boost .NET User Control development
productivity with tools such as intellisense, snippets, and the
like while the tools for XSLT are generally more limited. The
tradeoff is that XSLT is a fairly-concise language.
Additionally, XSLT is file-based in Umbraco which can make
integration with SCC systems easier and more direct. Finally,
.NET Controls are generally implemented as compiled assemblies
which makes access to an installation's file system a
necessity.
NB: with the recent (7 October 2008) Visual Studio
debugging configuration proposed by Niels Hartvig the use of
complex XSLT becomes more approachable as it can be readily
debugged.
Niels Hartvig's XSLT Rule of Thumb:
any single XSLT macro larger than 25 lines should be examined
for possible optimization of the XSLT or conversion to another
implementation format such as .NET User Controls.
Participants:
Paul
Jessica
Per
Matthew
Rob
Michael
John