Browse by Tags
All Tags »
Orchard (
RSS)
If you’ve ever tried to test Orchard part drivers, you may have been blocked by the fact that the methods on drivers are protected. That, fortunately, doesn’t mean they are untestable. Those methods are still accessible through explicit interface implementations. In particular, drivers implement IContentPartDriver, which is defined as follows. public interface IContentPartDriver : IDependency { DriverResult BuildDisplay(BuildDisplayContext context); DriverResult BuildEditor(BuildEditorContext context); DriverResult UpdateEditor(UpdateEditorContext context); void Importing(ImportContentContext context); void Imported(ImportContentContext context); void Exporting(ExportContentContext context); void Exported(ExportContentContext context); IEnumerable<ContentPartInfo>...
I really like jQuery’s pattern of attribute getters and setters. They are fluent and work really well with HTML and XML DOMs. If you specify a value in addition to the name, it’s setting, otherwise it’s getting. In C#, we have an OK API for XML, XElement, but it’s not as easy to use as jQuery’s attr methods. It is also missing the flexibility of Javascript with regards to parameter types. To recreate the simplicity of attr in C#, I built a set of extension methods for the most common simple types: var el = new XElement("node"); el.Attr("foo", "bar") .Attr("baz", 42) .Attr("really", true); var answer = el.Attr("baz"); The element built by this code looks like this: <node foo="bar"...
It is often useful to see what database queries were made during a specific request in Orchard. There are quite a few ways to do this (you can trace right from SQL Server , or you can use Mini-Profiler for instance), but this morning Sébastien showed me a really easy one that I thought I’d share. Find the log4net.config file in /src/Orchard.Web/Config and edit it to add the following tag: <logger name="NHibernate.SQL"> <priority value="DEBUG" /> </logger> Restart the application, then hit the URL you want to test, and look at your logs in App_data/logs. You should see new entries looking like this: 2013-04-03 18:57:30,367 [17] NHibernate.SQL - SELECT warmupsett0_.Id as Id575_0_, warmupsett0_.Urls as Urls575_0_...
If your hosted environment does not give you a staging site and the means to swap it easily with the production environment like Azure Cloud Services do, or if you don’t have a staging database, or if you just need to take your site offline for the public while you perform data updates in the admin, you may be wondering what solutions you have, if any. IIS has an app_offline.htm feature that you can use, that will serve a static page for all requests but that’s rather brutal as it does not just take the site offline for your users, it also does so for you. While that file exists, you can do absolutely nothing with your site. You cannot access the admin, you cannot preview your changes, nothing. So when you flip the switch back, it’s anyone’s...
The multi-tenancy feature in Orchard enables you to host multiple sites within the same Orchard instance. It’s not a a security feature, just a way to improve site density, and to enable you to save on hosting costs. Nevertheless, a request to a specific existing tenant should never be answered with a page from another tenant. Ever. There is however a fallback mechanism that enables one tenant to handle all requests that weren’t identified by another tenant. While this could be considered useful in some scenarios, I’m hereby declaring it bad practice. If for any reason a tenant fails to start, for example, requests to that tenant are going to fall back. Even if you were in a scenario where you considered fallback to be useful, this is an unexpected...
Placement.info is an XML file that orchestrates the different parts of a content item and sends each of the shapes they create into specific local content zones. If the previous sentence sounded confusing to you, fear not, this post is for you. When writing an Orchard theme, more often than not, you know exactly what parts exist in your content type, and you know where you want them to render. Placement can be extremely powerful, but it’s rather abstract and it reverses the usual logic of placing contents on a page. What most people really want to do is write a template with simple markup and placeholders inside that markup for the rendering of specific parts such as title, summary, tags, etc. Placement forces you to dispatch those part shapes...
If you want to create a simple widget in Orchard, such as a box of social links, you have three possibilities: Find a module on the gallery or write one yourself, but there is overhead associated with modules, which may make this overkill. Use an HTML widget and paste a bunch of HTML and Javascript, hoping administrators of the site don’t break it accidentally. I don’t like this, it feels like a hack. Create a simple widget, following the instructions in this post. First, let’s create a content type (in the admin, go to Content / Content Types and click “Create new type”) and call it “Social Links”. Add the widget and identity parts. Those are the only ones you really need: Uncheck creatable and draftable, add the “Widget” stereotype (with an...
This quick tip will show how you can write a custom view for a custom controller action in Orchard that does not use the current theme, but that still retains the ability to use shapes, as well as zones, Script and Style helpers. The controller action, first, needs to opt out of theming: [Themed( false )] public ActionResult Index() {} .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode...
With the imminent release of Orchard 1.5, the number of built-in modules in the default distribution is getting quite impressive, if not intimidating. Now may be a good time to give new and old users a tour of what comes out of the box. Who knows, we may discover a hidden nugget or two along the way… I just finished writing a massive documentation topic that describes all Orchard features that come with the source code and WebPI distributions: All built-in Orchard modules described I added the guide to the official Orchard documentation site. It details what modules come in the default package, which are only available from the source code package or from the gallery, and also mentions which are enabled by default. Documentation, like everything...
By default, when Orchard displays a content item such as a blog post in a list, it uses a very basic summary template that removes all markup and then extracts the first 200 characters. Removing the markup has the unfortunate effect of removing all styles and images, in particular the image I like to add to the beginning of my posts. Fortunately, overriding templates in Orchard is a piece of cake. Here is the Common.Body.Summary.cshtml file that I drop into the Views/Parts folder of pretty much all Orchard themes I build: @{ Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem; var bodyHtml = Model.Html.ToString(); var more = bodyHtml.IndexOf( "<!--more-->" ); if (more != -1) { bodyHtml = bodyHtml...
More Posts
Next page »