Copied to clipboard

Flag this post as spam?

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


  • Jesper Ordrup 1000 posts 1478 karma points MVP
    Feb 14, 2013 @ 18:19
    Jesper Ordrup
    0

    umbraco.library.renderTemplate

    Hi all,

    I'm using umbraco.library.renderTemplate to render boxes / widgets on a page. So from frontpage I have a macro that does the following

    For each box
       renderTemplate(boxid)

    The above is cool. It allows renderTemplate to run in the context of the box as being the currentPage. But say I put a macro on the template. How can it get access to the currentPage - and still keep the box context too? This would allow my boxes to behave differently on each page.

    Or another approach working on content boxes?

    Best
    Jesper

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Feb 14, 2013 @ 19:04
    Lee Kelleher
    1

    Hi Jesper,

    For uComponents RenderTemplate control (which is effectively the same as what you are doing), we have a custom property for passing through values from the current page to the "widget" pages.

    It uses "HttpContext.Current.Items" to store the data/value.

    Cheers, Lee.

  • Jesper Ordrup 1000 posts 1478 karma points MVP
    Feb 14, 2013 @ 20:10
    Jesper Ordrup
    0

    Thx lee,

     

    This looks cool - unfortunately I'm in a xslt loop :-) 

    Also the template could contain an xslt macro (could change)

     

     

    Best

    J

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Feb 14, 2013 @ 20:20
    Lee Kelleher
    1

    Hi Jesper,

    There is an XSLT extension for getting the value...

    umbraco.library:GetHttpItem('whatever')

    ... but couldn't find anything that could set the value. :-(

    Cheers, Lee.

  • Jesper Ordrup 1000 posts 1478 karma points MVP
    Feb 15, 2013 @ 02:16
    Jesper Ordrup
    101

    Found a way :-)

    The Macro RenderAllBoxes sets the current PageId in session before looping through the boxes. Like this:

    <xsl:value-of select="umbraco.library:setSession('contextPageId',$currentPage/@id)"/>
    <xsl:for-each select="$box/values">
    <xsl:value-of select="umbraco.library:RenderTemplate(@id)" disable-output-escaping="yes"/>
    </xsl:for-each> 


    The template and any macro defined in the template will be able to access both the box context (currentPage) or the page context using contextPageId. Xslt example:

    <xsl:variable name="contextId" select="umbraco.library:Session('ContextPageId')"/> <xsl:variable name="contextPage" select="umbraco.library:GetXmlNodeById($contextId)"/> Box context nodeName: <xsl:value-of select="$currentPage/@nodeName"/> <br/>Page "the real" nodeName: <xsl:value-of select="$contextPage/@nodeName"/> 

     

    Now I have "selfcontained" box renderings that have access to the page context allowing me to let the box rendering react on both.

    Best
    Jesper

     

     

     

     

     

     

     

  • 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