Copied to clipboard

Flag this post as spam?

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


  • Stephen 204 posts 246 karma points
    Aug 28, 2011 @ 20:56
    Stephen
    0

    Display random page/text

    My Clients want the ability to enter a weekly tips, simple text and a date.  I need to be able to display a randomly selected weekly tip on the homepage, preferably in scrolling text left to right and have a tips page will display all of them. So i have two questions

    1.  Am i best having a Tips and TipItem doc type that are not accessible via the main nav that i can tap into

    2.  Are there any projects will pull in a random page and display in a scoller?

    Thanks,

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Aug 28, 2011 @ 21:19
    Rich Green
    0

    Hey Stephen,

    I usually have a separate 'Settings' section outside of the site for situations like this, something like:

    -- Content

    ---- Home

    -------- About Us

    -------- Contact Us

    -------- etc.

    ---- Settings 

    --------Tips

    ---------- Tip 1

    ---------- Tip 2

    As for pulling out the random nodes you can use the xslt from here http://stackoverflow.com/questions/1389127/randomly-choose-a-node-in-xslt

    Cheers

    Rich

  • Stephen 204 posts 246 karma points
    Aug 28, 2011 @ 23:14
    Stephen
    0

    Hey Rich thanks for the feedback...

    Is there a reason to set this up outside the main content? I'm new to umbraco and often wondered where I should put things that are not necessarily HTML content but take care of things like lists for drop down selections in a form, would this be applicable to that?

    Cheers,

    Stephen

  • Rich Green 2246 posts 4008 karma points
    Aug 29, 2011 @ 00:30
    Rich Green
    0

    Hey Stephen,

    I always have a settings section, however in this case possibly I would have it like this:

    --Content

    ----Home

    ------ Tips

    -------- Tip 1

    -------- Tip 2

    It's just a matter of preference or  whatever is easier for the content editor to edit in this case.

    It's up for discussion when content is not content (as in this case the Tip will not be rendered on it's own, only in the context of the homepage).

    As for dropdowns in a form, yes I always put these in settings over the drop down datatypes as the user can edit them.

    There's no 'right' way but I'd most sites I've seen other developers set up have a settings section of some type.

    Cheers

    Rich

     

     

     

  • Stephen 204 posts 246 karma points
    Aug 29, 2011 @ 13:56
    Stephen
    0

    thanks Rich, i think i'm going to include a image and a tip, would the structure still apply?

     

     

  • Stephen 204 posts 246 karma points
    Aug 29, 2011 @ 15:06
    Stephen
    0

    Hey Rich, using that code below but i'm getting no output? Am i doing this right?

    <?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.ExsltMath="urn:Exslt.ExsltMath"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltMath">

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

    <xsl:param name="currentPage"/>

    <!-- This should probably be a macro parameter so you can use this elsewhere-->
    <xsl:variable name="parentNode" select="1381"/>

    <xsl:template match="/">

            <xsl:variable name="numberOfNodes" select="count(umbraco.library:GetXmlNodeById($parentNode)/node)"/>

            <xsl:variable name="randomPosition" select="floor(Exslt.ExsltMath:random() * $numberOfNodes) + 1"/>

            <xsl:variable name="randomNode" select="umbraco.library:GetXmlNodeById($parentNode)/node [position() = $randomPosition]"/>

            <!--
              You now have the node in the $randomNode variable
              If you just want the id then you can do an XPath query on the variable
              or you can modify the XPath above to get the property you are after rather than
              the whole node
            -->

      <xsl:value-of select="$randomNode/tmQuote" />
      <img src="{$randomNode/@nodeName/hpImage}" alt="" title="" class="hpImage" />
       

    </xsl:template>
    </xsl:stylesheet>

     

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Aug 29, 2011 @ 16:05
    Bjarne Fyrstenborg
    0

    Hi Stephen

    I have done something similar to display a random quote, where a had Quotes and Quote doctypes... and the Quote doctype could have the properties I needed: http://our.umbraco.org/forum/developers/xslt/20274-How-to-display-random-quote

    Furthermore there is this wiki http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/xslt-getting-a-random-document-when-the-page-reloads where it uses root instead of a specific doctype in the first link..

    Bjarne

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 29, 2011 @ 16:06
    Dennis Aaen
    0

    Hi Stephen,

    The reason I think you get no output when using the code you have posted is that this uses the old XML schema. And I assume that you are using a newer version. Probably 4.7 right?

    If so, try something like this and see if you have better luck.

    <?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.ExsltMath="urn:Exslt.ExsltMath"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltMath">

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

    <xsl:param name="currentPage"/>

    <!-- This should probably be a macro parameter so you can use this elsewhere-->
    <xsl:variable name="parentNode" select="1381"/>

    <xsl:template match="/">

    <xsl:variable name="numberOfNodes" select="count(umbraco.library:GetXmlNodeById($parentNode)/* [@isDoc])"/>
    <xsl:variable name="randomPosition" select="floor(Exslt.ExsltMath:random() * $numberOfNodes) + 1"/>
    <xsl:variable name="randomNode" select="umbraco.library:GetXmlNodeById($parentNode)/* [@isDoc][position() = $randomPosition]"/>

    <!--
    You now have the node in the $randomNode variable
    If you just want the id then you can do an XPath query on the variable
    or you can modify the XPath above to get the property you are after rather than
    the whole node
    -->
    <xsl:value-of select="$randomNode/tmQuote" />
    <img src="{$randomNode/@nodeName/hpImage}" alt="" title="" class="hpImage" />

    </xsl:template>
    </xsl:stylesheet>

    A useful tool when you, as you find something xslt based on the old form can be Tommy Poulsen's online xslt convert tool. You find the link here.

    http://blackpoint.dk/umbraco-workbench/tools/convert-xml-schema-to-45-.aspx.

    The way you can see the xslt code uses the old form can often be in such <xsl:variable name="numberOfNodes" select="count(umbraco.library:GetXmlNodeById($parentNode)/node)"/>. Node does not exist in the new schedule, this has been replaced by a [@ isDoc].

    I hope it can help you on the right track

    /Dennis


  • Stephen 204 posts 246 karma points
    Aug 29, 2011 @ 16:44
    Stephen
    0

    Hey Dennis,

    Thanks for the post and link the convert tool.  Still not working with the new code...does not seem to be getting the random node..i found another XSLT that can get a random from a media folder that works well...would still like to work out how to do it on a folder though

Please Sign in or register to post replies

Write your reply to:

Draft