Specifying query and parameters for Sitecore Treelist Field Source

Just before the Christmas break I got into a conversation with Robbert Hock on Slackchat about Sitecore fields and specifying a queryable source for the Treelist field in Sitecore 8.1. As you may be aware, several of the Sitecore fields support specifying an XPath query in the field source and others support an enhanced syntax using parameters.

From Sitecore 7.2 Update-2 the Treelist and TreelistEx fields also started to support specifying a query in the Source field.

Released Sitecore CMS and DMS 7.2 rev. 140526 (7.2 Update-2)
Field types
The Treelist and TreelistEx classes now support Sitecore query in the source for these field types. (319249)

Read More

Advertisements

Custom Glass.Mapper Data Handlers – Part 2

In a previous post about extending Glass Mapper to handle custom data types I shared some code which I felt was overly verbose and I did not like the amount of code that had been copy/pasted. The example I used was a fairly trivial one, but it’s always good practice to try avoid copy/paste in case some point in the future the base implementation is changed. It might not always be clear to future developers how that piece of code had come about.

In that original post, Mike Reynolds (a.k.a sitecorejunkie) suggested use of the Decorator Pattern to wrap an instance of the base mapper and delegate some of the methods. Well it got me feeling uneasy and I finally found a little time to come back and clean that code up, I went a slightly different route and decided to use constructor overloading.

Read More

Extending Media Item Templates with Custom Glass.Mapper Data Handlers

On a recent project I needed to add a couple of fields to Media Items templates in order store some additional data. We are using the Glass Mapper ORM in our project and out of the box there are two fields which we can map to: Image and File. I also needed to retrieve the file size, which neither of these fields returned either.

It turned out to be relatively simple to extend Glass Mapper and add our own custom data handler to map the additional fields.

Read More

Custom Sitecore field for storing Key/Value Data with Lookups

On a recent question about storing custom field attributes for a field in Sitecore on Stackoverflow just over a week ago I suggested looking at the Name Value List and Name Lookup List field types. I have to admit that I have never used this field before, but knew of their existence and the general premise of the field.

Name Value List field

If you are unaware of this field, it allows you to store Key/Value pairs of data. The underlying raw value of the field is then stored as url type parameters:

key1=value1&key2=value2&key3=value3

Read More

Hiding Content Editor Fields Depending on Selected Values

tl;dr Custom Field which hides other fields in the Content Editor depending on the selected value

A recent question on Stackoverflow asked if it was possible to hide fields in the Sitecore Content Editor when certain values are selected. This is a pretty common (and easy task) on any normal web site and it makes sense from a usability point of view to only show those fields which are relevant to the user. I gave a half answer to the question that a Composite Custom Field could be created to fire off the relevant Javascript and hide the sibling fields on change. I was unsure however how to hide the fields on document load.

Read More