Nibble

Umbraco Content Picker Datatype

Umbraco has a bunch of default data types. One of them is the content picker. You can find the data types in the developer section of umbraco. When you are unfamiliar with umbraco basics like document types and data types, read this great article on the official umbraco blog http://umbraco.org/blog/2007/12/3/dec-3-umbraco-basics-document-types

So when do you use the content picker datatype, lets say you have a site which has a listing of staff members and on your homepage you want to display a ’staff member of the month’. So on your homepage document types you create a new property ’staff member of the month’ and choose ‘Content Picker’  as Type.

When you go to the content and select your homepage you will have the option to select the ’staff member of the month’. When clicking on choose a new window will open with a treeview of the content and there you only need navigate and select the ’staff member’.

image 

 

After saving the document, the nodeid of the staff member will be saved as ’staff member of the month’. So to display this on our homepage we need to write a little xslt. Because a <?UMBRACO_GETITEM field=”#staffmemberofthemonth”/> will only display the nodeid.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE xsl:Stylesheet [ &lt;!ENTITY nbsp “&#x00A0;”> ]>

<xsl:stylesheet

version=”1.0″

xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”

xmlns:msxml=”urn:schemas-microsoft-com:xslt”

xmlns:umbraco.library=”urn:umbraco.library”

exclude-result-prefixes=”msxml umbraco.library”>

 

 

<xsl:output method=”xml” omit-xml-declaration=”yes”/>

 

<xsl:param name=”currentPage”/>

 

<xsl:template match=”/”>

<a href=”{umbraco.library:NiceUrl($currentPage/data [@alias = ’staffmemberofthemonth’])}”>

<xsl:value-of select=”umbraco.library:GetXmlNodeById($currentPage/data [@alias = ’staffmemberofthemonth’])/@nodeName”/>

</a>

</xsl:template>

 

</xsl:stylesheet>

So $currentPage/data [@alias = ’staffmemberofthemonth’] will get the nodeid of our staff member and with the umbraco library method GetXmlNodeById we can get the xml of the node and have acces to its properties.

3 Comments so far

  1. Soeren Sprogoe on April 18th, 2008

    Nice intro to the content picker!

    Keep them articles coming :-)

  2. Tim Geyssens on April 19th, 2008

    Thanks Soeren,

    Sure there will be loads coming… If you have ideas or suggestions for an article, shoot !

  3. Kasper Hansen on May 28th, 2009

    Hi. I’m using Umbraco 4.0.1. I have made a custom property where i’m using a content picker as one of my properties. But I have a problem, when I want to clear the content picker..

Leave a Reply