Blocks
Blocks is a module for Orchard allowing you to create content-managed regions in any view.
The basic usage is very simple:
@Display.Block(Name: "AnIdentifier")
This will create a Block which you can edit from the content management interface. It's actually just a Content Type called "Block" which by default will only display BodyPart - so it's just a simple editable HTML region. But, because internally it's a fully blown content item, you can add new parts to it if you wished (e.g. an image gallery, a map, etc.).
I had two requirements with this module:
1. From a view to be able to insert a named, editable block of content
2. Be able to provide default HTML content for the block directly in the view, with full HTML Intellisense and syntax highlighting from Visual Studio - this is tricky because it means we can't just pass in a text string!
Actually you can just pass in a text string, as follows:
@Display.Block(Name: "AnIdentifier", DefaultContent:"Here's some content")
The problems with this start when you want HTML tags as well, things start looking messy very quickly:
@Display.Block(Name: "AnIdentifier", DefaultContent:"<p class=\"bigText\">Here's some content</p>")
I just don't like passing around HTML in strings and those escape characters look ugly. Fortunately since we're using Razor syntax there's a neat way to solve this problem:
@{
Func<dynamic, object> block = @<text><p class="bigText">Here's some content</p></text>;
}
@Display.Block(Name: "AnIdentifier", DefaultContent:block)
Razor allows you to define HTML delegates - unfortunately it requires you to declare the type of the delegate which doesn't look too great, but I much prefer being able to edit the content as proper HTML with designer intellisense support. Everything inside the <text> tags works as normal HTML editing, and you can even break off into further code sections.
I also considered using Capture or something similar to handle capturing HTML, but in the end this method seemed neatest.
The module is available here on the Orchard Gallery: https://gallery.orchardproject.net/List/Modules/Orchard.Module.Downplay.Blocks