First Details of New ASP.NET MVC Macros in Umbraco v5 CMS

August 19, 2011

Yesterday, we learned more about the syntax of macros being developed for Umbraco version 5, codenamed Jupiter. Yes, there’s a new round of changes; no, not every Umbraco developer will welcome that fact yet again. But the result continues to be evolutionary, and on the right path.

In a new blog post, Umbraco contributor Shannon Deminick demonstrated the new class of ASP.NET macros whose cryptic name (there are plenty of cryptic names in Umbraco) is Partial View macro. Think of it as a perfected Razor macro, but with better support for strongly-typed components.

Here’s one example of a server-side macro using the Partial View construct, courtesy of Deminick:


@Html.UmbracoMacro("blah")

public Content CurrentNode { get; }
public dynamic MacroParameters { get; }

h2Names of child nodes/h2
@foreach (var child in Model.CurrentNode.ChildContent().AsDynamic())
{
p
Child node name: [email protected]/b
/p
}

Here you see how easily the Razor code (which is still Razor by the way, or technically a .CSHTML file) co-exists with the markup code. Although this is actually a throw-away component that does less than your average “Hello, world,” you see the basic structure: The @HTML header starts things off now. There’s strong typing by way of variables that represent where the current node is in the database tree (an article in an Umbraco folder is one example of a node) and the parameters being passed to the macro, which may number from zero to a handful. (According to a recent addition to the Umbraco wiki, “Depending on the macro chosen, we will hopefully be able to dynamically populate the macro parameters instead of having to manually type them in like in v4.”) Note the Content data type, which is an indicator of how Razor uses dynamic typing here.

The foreach loop uses a C# construct, which is a simplified way to say “for all elements of a list” without creating an iterator variable like in C++. Just like in Umbraco v4, the @ acts as a type of switch, telling the parser, “I’m not talking to you in HTML for the moment, I’m switching to Razor.”

“Razor views allow you to define public properties, methods, etc. inside of the Razor markup,” writes Deminick. “So if we want to have strongly typed parameters for our Partial View Macros which can be set based on Macro parameters in [Umbraco's] rich text editor, all we have to do is declare them.”

What does this mean, really? Modern CMS packages are limited in terms of the types of functionality they enable. As a result, blogs tend to act like all the other blogs. When you’re running a blog, and you can’t have an article stored in one department access an image that was added to the still store via an article in another department, that’s a database design issue created by the makers of the CMS. And it’s those people who have to solve the issue; until then, you’re stuck.

You are never stuck with Umbraco if you know what you’re doing. Enabling an image to be just as accessible through an article on one tier of the tree (one node in Umbraco) as it is from another node, is a matter of developing the tree architecture right to begin with. And if you’re the one doing it, it suddenly becomes a possibility.

The latest community technology preview of Umbraco v5 (which does not have the latest enhancements yet) is available from Codeplex.

Article source: RRW http://feedproxy.google.com/~r/readwriteweb/~3/XqILbpYYpcc/first-details-of-new-aspnet-mv.php

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Like Box

Links

  • 4 Hour Workweek Blog
  • All Things Digital
  • Beyond The Pedway
  • Business Hackers
  • Entrepreneur.com
  • Fast Company
  • Gigaom
  • Hacker News
  • Jonathan Fields
  • Mashable
  • Mixergy.com
  • Read Write Web
  • Seth Godin's Blog
  • Startup Nation
  • TechCrunch
  • The Next Web
  • Venture Beat
Plugin from the creators of Brindes Personalizados :: More at Plulz Wordpress Plugins