Skip to main content

Posts

Showing posts with the label Rendering

5 Tips and Tricks for Renderings Using Ajax

Eventually a component on a page is going to need to pull in some new information and you don't always want to reload the whole page. Making use of Ajax allows you to avoid a full reload but when you use Ajax with Sitecore there are a few important things to keep in mind: Make sure you set up your controller to function with the Ajax call.  Are you sending back some data, the whole rendering, or are you just updating something internally? Be ready to handle whatever is coming into or out of the controller. Note that if the Ajax function is posting data you must add [HttpPost] before the controller method. Regardless of how you get to your controller - there won’t be Sitecore context! Your controller has no idea what the user was doing or where they were on your site when the Ajax call was made. You need to pass all the information in your model to the controller including the data item and anything else relevant for your controller to give context. One way to give context is ...

A Simple Site Map

Similar to creating a menu – creating a site map is even easier, there are modules that can do this but with a little preparation it can be very easy to create yourself. To start we are assuming every template used for the pages includes some ‘base template’ for common aspects for all pages. To do this, create (or select if already created) the Base Template with the information you want to have and to that base template, add: InSiteMap: Checkbox Then create or modify the Page templates with the other information you want. From those templates, click to the Content tab, and select the Base template to be included: In the Standard values for the base template, you may want to have InSiteMap checked so that it will be on by default for all the pages. For the sitemap itself, we’re going to create a rendering and then we can place it wherever we would like. The rendering creates a basic nested list of all the items that have InSiteMap checked. < xsl:template match = " * ...

External and Internal Links as Items

I ran into a problem creating the navigation for the footer rendering on a page – On there I needed to have links to the following pages: terms, contact, careers, and the sitemap. The problem arose when trying to add ‘Contact’ and ‘Careers’: ‘Contact’ was a few levels down in the tree of content items and ‘Careers’ was an external page. Initially, I had a checkbox in the template of each page for if the item was in the footer (ie: InFooterNav checked) and then the XSLT file would go through the entire list of items to find what would be in the footer navigation. It wasn’t an ideal solution when so few items had the tag in the entire site and it did not help with my external link at all. Thus was born: The Link Template! The new template basically consisted of: Link Data: Link: General Link //This is the link to our item or the URL for the external page Nav Title: Single Line Text //The title we want to have displayed in our menu – this is the same as in my regular items Target:...

A Simple Single Level Menu with Rounded Edges

After taking some time to figure this out, I thought I’d share my approach to a simple single level menu rendering with rounded edges. Initially, the idea here is very straight forward – create a list, style it, voila! Unfortunately, Round edges and dynamic content make it a little less forgiving. Here is an Example of what we are trying to achieve: Each of these items would be a sub item in the site, all at the same level  under ‘/Sitecore/Content/Site’ In our XSLT  rendering we need to grab the list, and apply the appropriate styles to the appropriate items, notably: The first item needs to have a round corner on the left, the Last item needs to have a round corner on the right, and the inner items need to have borders around them all – and we need to be able to Hover for a different effect. To do this I did the following: < xsl:template match = " * " mode = " main " > < ul id = " MainNav " > < xsl:for-each select = " $Sit...