XSLTSearch Umbraco Media Section

I am currently working on a website which has a media gallery in it (functionally similar to JD Smooth Gallery but written in YUI)

Basically I have a gallery of images and some meta data (descriptions, titles) etc defined in the Umbraco Media section.

Document Type

Document Type with Media Picker
In my Document Type I have a Media Picker which allows you to select the Media. The alias for my field is ‘gallery’.

I have modified XSLTSearch so that it can be configured to treat certain fields as Media and will search the Media section.

XSLTsearch Macro

You will need to add a new field to the XSLTSearch Macro with an alias of “mediaFields” in which a comma separated list of fields containing media can be placed.

Here is a sample macro statement from Umbraco v4:

<umbraco:Macro runat=”server” Alias=”XSLTsearch”
macroAlias=”XSLTsearch”
source=”-1″
searchFields=”@nodeName,metaKeywords,metaDescription,bodyText,gallery”
previewFields=”bodyText,gallery,metaDescription,metaKeywords”
mediaFields=”gallery”
previewType=”beginning”
searchBoxLocation=”bottom”
resultsPerPage=”5″
previewChars=”255″
showPageRange=”1″
showOrdinals=”0″
showScores=”0″
showStats=”0″>
</umbraco:Macro>

You will also need to replace the XSLTsearch macro with the one I have modified (based on the latest v2.7 of the macro).  Download the modified XSLTsearch here.

Umbraco GetMedia Bug

Incidentally there appears to be a possible bug/feature in Umbraco if you want to be able to select a Media Folder in the Media Picker.  The Umbraco function “umbraco.library:GetMedia” will not work unless you add an Upload field to the Media “Folder” data type, with an alias of “umbracoFile”.

  • You do not have to add the extra Upload-field along with your mediapicker, GetMedia returns a nodeset, so in order to grab anything below the folder you picked with the mediapicker, do this:
    <xsl:if test="./data[@alias='yourMediapickerProperty'] != ''">
    /umbraco/ImageGen.aspx?image=<xsl:value-of select="umbraco.library:GetMedia(./node/data[@alias = 'yourMediapickerProperty'], 0)/data[@alias='umbracoFile']" />&width=xxx
    </xsl:if>

    As you see there's still an alias called umbracoFile. It's is hardcoded.
    See more here under MediaCurrent:
    http://umbraco.org/documentation/books/macro-pa...
  • Adz
    Thanks for the tip - I hadn't read that book before!

    It turns out that there is a bug (in Umbraco v4 beta at any rate) which was causing the problem with the media folder. If you want to grab a media folder, and all of its content, it wasn't possible - it simply didn't work.

    This has now been fixed in the latest code however.
  • Simon Justesen
    Okay - I haven't used Umbraco 4 that much since it's still beta, except for some light testing :)
  • Tim_Int
    Exactly what is the output of this supposed to look like? Links to the pages that have matching media, or links to the media?
  • Adz
    It returns links to the pages which reference the media eg. via an
    umbraco media picker. It is based on the XsltSearch package so more
    detailed instructions can be found there. Let me know how you get on?
  • Seth
    Your XSLT gives me errors when I try to save it in regards to this line: </input> <input>
    I just changed it to this (which is what it is in the original): </input> <input type="submit" value="Search" class="submit" />
    but it still gives me Error parsing XSLT file when trying to run it real time.
  • Seth
    The runtime error in the XSLT was related to me have two property types named the same thing but i am still not getting any results from the media library, it is all from content.
blog comments powered by Disqus