Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ivan 139 posts 302 karma points
    Feb 09, 2010 @ 21:37
    Ivan
    0

    Filter entries with a select box in frontend

    Hello:

    I want to filter entries of a page by year using a select box in frontend (public website), so the user can filter the info of his interest.

    You can check the following example:

    Thanks a lot for your help!!

    Ivan

  • sim0n20 7 posts 27 karma points
    Feb 09, 2010 @ 22:33
    sim0n20
    0

    you could use umbraco.library:RequestForm() to request the value of your select box on post back and then use the value to filter your results against the year part of the publication date of your entries

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Feb 09, 2010 @ 23:29
    Chriztian Steinmeier
    0

    Hi Ivan,

    I'd implement this with a GET form that appends the variable year to the URL (e.g. ?year=2009)

    In the XSLT that renders the items you could then use umbraco.library:RequestQueryString('year') to get the selected value (if any) and filter the result by adding a predicate like the following to the XPath that selects the nodes to render; something like:

    <xsl:apply-templates select="$currentPage/node[starts-with(@createDate, $year)]" />

    (Obviously, you'd render the selectbox with the chosen year pre-selected as a courtesy to the user)

    Hope this gets you going, and feel free to ask for detailed examples if needed.

    /Chriztian

  • Ivan 139 posts 302 karma points
    Feb 10, 2010 @ 00:52
    Ivan
    0

    Thanks a lot guys!!

    You know, i discovered Umbraco two weeks ago and it was love at first sight.
    Finally a CMS where the only limit is your imagination...Well, and your programming skills :)

    I am working with XSLT for the first time and i do like it's potential for transforming XML structures. But im a totally newbie so Chriztian, if you can send me any example would b great.

    Thanks again for your help.

    Ivan

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 10, 2010 @ 09:26
    Thomas Höhler
    0

    Something like this can do it:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:th.library="urn:th.library" xmlns:ss4u.library="urn:ss4u.library"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets th.library ss4u.library ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:variable name="year" select="umbraco.library:RequestQueryString('year')"/>
    <form action="{umbraco.library:NiceUrl($currentPage/@id)}">
    <select id="year">
    <option value="2010">
    <xsl:if test="$year='2010'">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>2010</option>
    <option value="2009">
    <xsl:if test="$year='2009'">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>2009</option>
    <option value="2008">
    <xsl:if test="$year='2008'">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>2008</option>
    <option value="2007">
    <xsl:if test="$year='2007'">
    <xsl:attribute name="selected">selected</xsl:attribute>
    </xsl:if>2007</option>
    </select>
    <input type="submit" value="Search"></input>
    </form>
    <h1>Your results:</h1>
    <xsl:if test="count($currentPage/node[starts-with(@createDate, $year)]) &gt; 0">
    <ul>
    <xsl:for-each select="$currentPage/node[starts-with(@createDate, $year)]">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName" />
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    Not tested, but have something similiar for my Simple Search 4 Umbraco...

    hth, Thomas

     

  • Ivan 139 posts 302 karma points
    Feb 10, 2010 @ 12:13
    Ivan
    0

    I will give it a try, Thomas.

    Thanks ;-)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies