July 23, 2024

As a Sitecore beginner, we are very eager to know more and more about Sitecore.

The Content:

We first create the templates, which defines the structure of our content. — What all is needed Next, we create all the required items from these templates and fill them up with the required content. Know more..

The Presentation:

Next, we create layouts (ASPX Files) and sublayouts (ASCX User controls) defining the structure of the pages of our website. Sitecore, offers us the opportunity of code reuse, and hence, its always a good way to create our presentation components in such a way, that we can make most reuse of our presentation items. Know more..

Binding Presentation and Content:

Now, we know that our content is ready in the content items, and how our data will look is ready in our presentation — layouts and sublayouts.  So what remains is mapping our content on our presentation items, so that it is displayed on a page in a website. We have two ways of doing it.

Static Binding:

Static binding, as the name suggests, is something like hardcoding a value on a page. Its like knowing at compile time, what component will be rendered at which location. Lets take an example. In our website, we might have some portions on a page, which are common for all the pages, or atleast for some pages. Say a control which renders the company logo, or the search bar, or say the navigation component, or a footer with copyrights or social media icons etc. This is to make architecture of a site quite simple, in case of all those components and renderings, which are required on all the pages. Instead of taking the pains of adding them to each page individually, they can be added directly to the main layout — the main aspx page, responsible for the rendering — and thus save our as well as content editor’s time, in linking them to various content items, individually. An example of Static binding is as follows:

[sourcecode language=”xml”]
<sc:rendering id="Navigation" runat="server" renderingname="SiteNavigation"></sc:rendering>
<sc:sublayout id="Search" runat="server" path="/layouts/global/SiteSearch.ascx"></sc:sublayout>
[/sourcecode]

Dynamic Binding:

Dynamic binding, goes by its name. Various page components, — renderings and sublayouts are bound to their respective content, dynamically, on runtime. The binding takes place using placeholders — various placeholders as per requirement are added to the layout and the sublayouts, and different required presentation components, are assigned the placeholder key as per their rendering location. This is way, the rendering location of the various presentation components, can be managed as per requirement, and changed on runtime.

[sourcecode language=”xml”]
<sc:Placeholder runat="server" ID="phleftSidebar" Key="leftSidebar" />
[/sourcecode]

This way, Sitecore Supports better modularizing of your application as well as code reuse.  Again, to avoid adding various presentation components to each and every item of your site, its good to configure and add the bindings to the Standard Values of the respective item templates.

As far as using both the above is concerned, there isn’t a best case or worst case. Using them at appropriate locations of our site is the key and we can design an architecture which is best suited for our case.

Good Reads:

5 thoughts on “Sitecore Beginner – Static and Dynamic Binding

    1. Happy to know Dheer that you liked it.
      Thanks for sharing your views.
      And yes, you are absolutely right, LaunchSitecore is a great website for any Sitecore Developer to understand Sitecore!
      Keep Reading and Keep Sharing!

      Best,
      Varun Shringarpure

Leave a Reply

Your email address will not be published. Required fields are marked *