Skip to main content

Posts

Showing posts with the label XSLT

Getting Started with Breadcrumbs

Breadcrumbs have been covered by just about everyone so there are lots of examples that all seem to do things a Little differently. With that in mind I’m going to keep this short with my example and two other examples I’ve found that might also meet your needs and cover the basics for just about every xslt breadcrumb example you’ll find. The general idea: you’re at item c, in your tree the path is something like:  /sitecore/content/a/b/c and you want to display a pretty html list for a » b » c anywhere on your site.  You’ll always be dealing with the ancestors of your current item so you’ll be making use of $sc_currentitem/ancestor-or-self::… somewhere. You’ll need to go through each ancestor item and display it, probably checking to see if you’re at the last item so you don’t display a ‘»’ after the final item. You also need to make sure to not display unwanted ancestors in your breadcrumb, being /sitecore and /content in our case. So onto the examples! First is the Sitec...

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...