Copied to clipboard

Flag this post as spam?

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


  • marcelh 171 posts 471 karma points
    Sep 27, 2010 @ 00:01
    marcelh
    0

    Parent doesn't have childeren using contentRandom

    I'm trying to setup an xslt macro that randomly picks a content item under. However, when I try to use contentRandom parameter, nothing is passed to my macro and when I run the page in debug mode the message "Parent doesn't have childeren".

    The page selected in the contentRandom does have childeren, and even when I select the website root as parent, the message applies...

    Anyone has clue as to how to sort this out?

  • Rich Green 2246 posts 4008 karma points
    Sep 27, 2010 @ 10:20
    Rich Green
    0

    I don't know the exact answer to your question, however I would add one step at a time and see exactly where your problem lies as it sounds strange.

    Does your template and site run without errors when you do not use this macro?

    Can you set up this macro with a clean XSLT file and pass it a single parameter and print this parameter value out?

    If you can get to these points then there must be something wrong with your XSLT so I would advise posting your code and content structure here.

    Rich

  • marcelh 171 posts 471 karma points
    Sep 27, 2010 @ 10:28
    marcelh
    0

    Thanks for your reply. The site runs without any errors. The macro is very basic, it only outputs a copy-of the parameter node.

    When I run the page with umbShowDebugTrace, a red line appears in the trace notifying that "Error adding random node - parent (1050) doesn't have children!".

    I'm running on Umbraco 4.5.2.

  • Rich Green 2246 posts 4008 karma points
    Sep 27, 2010 @ 10:32
    Rich Green
    0

    Do any other macros cause this error, can you post your XSLT code here?

     

  • marcelh 171 posts 471 karma points
    Sep 27, 2010 @ 11:53
    marcelh
    0

    There are a few other macro's on the page, but they work as expected. When I remove those macro's, the error occurs. Here's the macro code:

    xml version="1.0" encoding="UTF-8"?>
    DOCTYPE xsl:stylesheet [
    ENTITY nbsp " ">
    ]>
    <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:param name="randomQuote" select="/macro/randomQuote"/>

    <xsl:template match="/">
    <pre>
    <xsl:copy-of select="$randomQuote"/>
    pre>
    xsl:template>

    xsl:stylesheet>

    In my point of view, the error does not occur when the xslt is processed but when the contentRandom macro parameter is accessed:

    umbracoMacro Macro loaded from cache (ID: 7, Quote Randomizer) 0,0162017798351466 0,000142 
    renderMacro Rendering started (macro: Quote Randomizer, type: 1, cacheRate: 0) 0,0162906179416658 0,000089
    umbracoMacro Xslt node adding search start (randomQuote,'1050') 0,016363532236639 0,000073
    umbracoMacro Error adding random node - parent (1050) doesn't have children! 0,0164113036712767 0,000048
    umbracoMacro Before adding extensions 0,0164573989152253 0,000046
  • Rich Green 2246 posts 4008 karma points
    Sep 27, 2010 @ 12:20
    Rich Green
    0

    Can't see any major errors here.

    Though I don't really understand this "When I remove those macro's, the error occurs. "  Are you saying this error only occurs when you remove the other macros? 

    Do your other macros have parameters?

    Maybe try starting again from scratch, new blank template, new XSLT file based on clean template, brand new macro with different parameter name and work from there as it seems like there's something real basic going wrong.

    Rich

     

  • marcelh 171 posts 471 karma points
    Sep 27, 2010 @ 12:29
    marcelh
    0

    I was already thinking that way. I downloaded the Umbraco sources and trying to set a breakpoint on the contentRandom function. If that doesn't bring a solution I might as wel start over blank.

    I ment to say, that when I remove all other macro's, the error still occurs, meaning it's only related to this macro.

    Has anyone used the contentRandom function? I can't find many references to this function, not the forum, not google or any blog posts.

  • marcelh 171 posts 471 karma points
    Sep 27, 2010 @ 12:49
    marcelh
    0

    Hmz, I tried it in another Umbraco website (same 4.5.2 version) I'm running, but the same error occurs...

  • Rich Green 2246 posts 4008 karma points
    Sep 27, 2010 @ 12:51
    Rich Green
    0

    I didn't realise there was a contentRandom parameter type! I just thought this was what you were naming your parameter, so sorry for that.

    I've never used this but have used other ways to grab random nodes, of which there are plenty of examples on google / here if you can't get this fixed.

    Rich

  • marcelh 171 posts 471 karma points
    Sep 27, 2010 @ 14:07
    marcelh
    0

    Well, you just found a new Umbraco feature today ;) Offcourse I could implement it in another way, but I can't stand it that there is this function but can't get it to work. Perhaps someone of the Umbraco team can shine a light on this?

  • marcelh 171 posts 471 karma points
    Sep 27, 2010 @ 18:25
    marcelh
    0

    And I found an Umbraco bug report today :( Having zoomed in at the macro.cs code, there are references to

    XmlNodeList sourceList = source.SelectNodes("node");

    Obviously the problem has to do with the old xml schema that has been used before, where elements were added as a "node" and not as "Element". I'll ask the team to update this. Solution would be not only to specify the parent element, but also the name of the child elements to select from.

    Not only the contentRandom macro parameter is affected, also the contentCurrent macro parameter is affected and will probably not work as expected.

  • Profiterole 232 posts 264 karma points
    Aug 17, 2011 @ 22:37
    Profiterole
    0

    Hi! I used this parameter a lot and since I updated (now in new schema) the contentRandom does not work anymore. How can I specify the name of the child elements?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 17, 2011 @ 22:54
    Chriztian Steinmeier
    0

    Hi Profiterole,

    If you're changing the source and re-compiling, use Select("*[@isDoc"]) to equal what "node" used to select.

    Otherwise, I'd recommend installing uComponents (it's almost a must-install anyway) and try out the RandomNode() extension.

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft