I'm lookin for a little sanity check with a implementation of shared content within a site. The site I'm building has several regions with largely the same content throughout, but some region specific pages and copy as well.
From the root node, I have:
Shared Content
Page 1 Content (Has Actual Content)
Region #1
Page 1 Content (Content Picker to Shared Content)
Region #2
Page 1 Content (Content Picker to Shared Content)
To select the shared content I'm using a content picker on a master document type. In my master template, I have a razor macro called ContentRenderer:
@inherits umbraco.MacroEngines.DynamicNodeContext
@if (Model.HasValue("UseContentFrom"))
{
var sharedContent = Library.NodeById(Model.UseContentFrom);
if (Model.NodeTypeAlias == sharedContent.NodeTypeAlias)
{
umbraco.library.RenderTemplate(sharedContent.Id);
}
else
{
<div class="row">
<div class="twelve columns">
<p style="color: Red;">
The document type of the content your trying to use doesn't match the document type
of your page.
</p>
<p>
Page Document Type: <strong>@Model.NodeTypeAlias</strong>
<br />
Shared Content Document Type: <strong>@sharedContent.NodeTypeAlias</strong>
</p>
</div>
</div>
}
}
Of note, is the call to RenderTemplate. Provided the document types match (which I check for), as soon as RenderTemplate is called, the Model node is effectively replaced with that of the shared content. This is great since I don't have to define new templates, or do any custom coding to spit out shared data. The downside is it is a little cumbersome to manage through the UI, and links etc end up pointing back to the shared content folder.
I think this is pretty good solution given my requirement, but I'd love to hear from the community to see if there is a better way to achieve this.
Shared Content With Razor
Hello,
I'm lookin for a little sanity check with a implementation of shared content within a site. The site I'm building has several regions with largely the same content throughout, but some region specific pages and copy as well.
From the root node, I have:
To select the shared content I'm using a content picker on a master document type. In my master template, I have a razor macro called ContentRenderer:
Of note, is the call to RenderTemplate. Provided the document types match (which I check for), as soon as RenderTemplate is called, the Model node is effectively replaced with that of the shared content. This is great since I don't have to define new templates, or do any custom coding to spit out shared data. The downside is it is a little cumbersome to manage through the UI, and links etc end up pointing back to the shared content folder.
I think this is pretty good solution given my requirement, but I'd love to hear from the community to see if there is a better way to achieve this.
Hi, Brent. There's also an excellent article in wiki that may interest you: http://our.umbraco.org/wiki/how-tos/creating-reusable-content
is working on a reply...