Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Using Synthesis with Blade
Synthesis features neat integration with Blade, a Sitecore presentation framework. This integration automates the conversion of Synthesis types into available Blade model types without defining an explicit Blade presenter.
What the heck does that last paragraph even say? It means you can define Blade views like this (.cshtml example):
When the Synthesis integration sees this, it automatically performs a conversion of the rendering's data source into the requested Synthesis type and returns it as the model. This enables you to quickly write renderings that have no idea Synthesis even exists!
Sitecore 7 introduces the idea of using index queries and Sitecore query expressions as rendering data sources. This means you may receive more than one item as a data source. Blade fully supports this kind of scenario with
ListPresenters. The Synthesis integration takes this a step further by automatically enabling list presenters with Synthesis objects. Check this out:
It's that easy - make your model an
IEnumerable<T> of a Synthesis type and you will get an enumerable set of data sources provided to you. It's fine to use this if you might get a single item as well; the enumerable will have one element. Note: at present only IEnumerable is supported, not derivatives of IEnumerable such as arrays or lists
Performance note: Currently, the multiple data source logic involves converting index items into Sitecore.Data.Item so this solution is appropriate for relatively small result sets (< 100 items) and/or with output caching. Once Sitecore 7 Update 2 launches, there will be an optimization available to pass through mapped index objects and eliminate this warning.
Synthesis also extends Blade's razor HTML helpers with some helpers for rendering Synthesis field types:
@Html.DateTimeFor(x => x.DateField) @Html.ImageFor(x => x.ImageField) @Html.FileLinkFor(x => x.FileField) @Html.TextFor(x => x.TextField) @Html.HyperlinkFor(x => x.LinkField)
These work as the xxxFor() form helpers in MVC, only for Sitecore field types. Most of them also have additional overloads that allow setting CSS classes, tweaking image width and height properties, setting page edit-ability, etc. HTML encoding is handled automatically by the helpers and Page Editor is fully supported.