Something I missed along the way is the ease with which you can add rendering parameters to a server control. Many of the examples we use in training use content items to show how easily the values that a control renders can be changed by a content author. Many times the update makes a lot of sense to become a parameter in the layout details themselves.
Let’s take the example of the Footer control (Footer.cs) that is used in Sitecore developer training and is part of both the Starter Kit and Office Core example sites. The Footer control looks to the content tree for its values. A “Copyright” item allows content authors to affect the values that appear in the footer of the page:
Let’s assume that, in addition to wanting to define the actual text in the Copyright (year, holder, text, etc), we want our content authors to define whether or not the link to the Terms of Use should appear in the footer at all. Now, this could certainly be accomplished in many ways. An addition of a checkbox field (“Include Link Text”, for instance) on the Copyright item itself would allow the Footer control to show this link or not depending on a content author’s wishes. For this example, though, let’s do it as part of the attributes of the control itself, in the hopes of a simple example leading to more complex real-world solutions.
The Footer control item (under Layout—>Renderings—>Footer Control) has a field in the Editor Options section that allows us to define the Presentation Template that will drive our new attribute:
Now, we can define a new template to hold these presentation attributes. For our simple example, we’ll only define one—a checkbox field that will allow a content author (or more accurately a page designer….someone responsible now for the look and feel of the site) to decide whether or not our link text will appear on pages that use this Footer control.
This new template inherits from the /sitecore/templates/System/Layout/Rendering Parameters/Standard Rendering Parameters template. We add our new IncludeTermsOfUse field to it.
N0w, if we choose to add the Footer control to a page, we can also set this new attribute:
And do a simple check for its value in our presentation code:
// ...Link to "Terms of Use" text
string link_text = "";
if (IncludeTermsOfUse=="1")
link_text = FieldRenderer.Render(copyright_item, _linkTextField);
