Copied to clipboard

Flag this post as spam?

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


  • Peter Drayton 29 posts 49 karma points
    Dec 12, 2011 @ 17:37
    Peter Drayton
    0

    Rendering a UserControl inside of an .xslt Macro

    Hi,

    I have a scenario where the Administrator of a site can choose what modules they want on the right hand side of the page.

    One of the Modules is a User Control. How would i go about doing that in Umbraco?

    The xslt is below:

    <?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:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:fulltextsearch.search="urn:fulltextsearch.search" xmlns:fulltextsearch.helper="urn:fulltextsearch.helper" xmlns:ucomponents.cms="urn:ucomponents.cms" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.io="urn:ucomponents.io" xmlns:ucomponents.media="urn:ucomponents.media" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.nodes="urn:ucomponents.nodes" xmlns:ucomponents.request="urn:ucomponents.request" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:ucomponents.urls="urn:ucomponents.urls" xmlns:ucomponents.xml="urn:ucomponents.xml" xmlns:autofolders.library="urn:autofolders.library"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary fulltextsearch.search fulltextsearch.helper ucomponents.cms ucomponents.dates ucomponents.io ucomponents.media ucomponents.members ucomponents.nodes ucomponents.request ucomponents.search ucomponents.strings ucomponents.urls ucomponents.xml autofolders.library ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
      <xsl:choose>
        <xsl:when test="name($currentPage) = 'umbNewsArticle'">
           <xsl:apply-templates select="$currentPage/ancestor-or-self::*/umbNewsArea/sidebarModules/*" />
        </xsl:when>
        <xsl:when test="name($currentPage) = 'NewsArchive'">
           <xsl:apply-templates select="$currentPage/ancestor-or-self::*/NewsArchive/sidebarModules/*" />
        </xsl:when>
        <xsl:when test="name($currentPage) = 'DateFolder'">
           <xsl:apply-templates select="$currentPage/ancestor-or-self::*/NewsArchive/sidebarModules/*" />
        </xsl:when>
        <xsl:when test="name($currentPage) = 'FullTextSearchPage'">
           <xsl:apply-templates select="$currentPage/ancestor-or-self::*/FullTextSearchPage/sidebarModules/*" />
        </xsl:when>
        <xsl:when test="name($currentPage) = 'umbHomepage'">
           <xsl:apply-templates select="$currentPage/ancestor-or-self::*/umbHomepage/sidebarModules/*" />
        </xsl:when>
        <xsl:when test="name($currentPage) = 'Page'">
           <xsl:apply-templates select="$currentPage/ancestor-or-self::*/Page/sidebarModules/*" />
        </xsl:when>
        <xsl:otherwise>
           <xsl:apply-templates select="$currentPage/ancestor-or-self::*/umbNewsArea/sidebarModules/*" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    <xsl:template match="MultiNodePicker">  
      <xsl:for-each select="./nodeId">
        <xsl:variable name="data" select="umbraco.library:GetXmlNodeById(.)"/>
        <xsl:choose>
        <xsl:when test="$data/@nodeName = 'Module1'">
          <div id="orlovsOpinion">
            <p class="text"><xsl:value-of select="//module1Text" disable-output-escaping="yes"/></p>
          </div>
        </xsl:when>
        <xsl:when test="$data/@nodeName = 'Module2'">
          <div id="meerkovoWeather">
            <p class="text"><xsl:value-of select="//module2Text" disable-output-escaping="yes"/></p>
            <xsl:variable name="image" select="//module2Image"/>
            <xsl:if test="$image != ''">              
              <xsl:variable name="media" select="umbraco.library:GetMedia($image, 0)" />
              <img width="70" height="70" alt="Meerkovo Weather" src="{$media/umbracoFile}" />
            </xsl:if>  
          </div>
        </xsl:when>
        <xsl:when test="$data/@nodeName = 'News Archive'">
          <div id="archivedPosts">
            <h2>Archived Posts</h2>
            <ul>
              <xsl:for-each select="umbraco.library:GetXmlNodeById(1064)/DateFolder/DateFolder">
                <xsl:sort select="./../@nodeName" data-type="number" order="descending" />
                <xsl:variable name="monthname" select="umbraco.library:FormatDateTime(concat(./../@nodeName,'-',@nodeName,'-11T10:24:46'),'MMMM yyyy')" />
                <xsl:variable name="yearname" select="./../@nodeName"/>
                <xsl:if test="position() &lt; 5">
                  <li>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                      <xsl:value-of select="$monthname"/>
                    </a>
                  </li>
                </xsl:if>
              </xsl:for-each>          
              <li><a href="/news-archive.aspx">See All</a></li>
            </ul>
          </div>
        </xsl:when>

        <xsl:when test="$data/@nodeName = 'Newsletter Signup Form'">
            <!-- THE USER CONTROL NEEDS TO GO IN HERE?
            <umbraco:Macro Alias="RegisterMember" runat="server"></umbraco:Macro>
             -->
       
         </
    xsl:when>
        <xsl:otherwise>
          <div class="mpu">
            <xsl:variable name="image" select="$data/mpuImage"/>
            <xsl:if test="$image != ''">              
              <xsl:variable name="media" select="umbraco.library:GetMedia($image, 0)" />
              <img width="228" height="228" alt="{$data/@nodeName}" src="{$media/umbracoFile}" />
            </xsl:if>  
          </div>
        </xsl:otherwise>
        </xsl:choose>
        </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

  • Peter Drayton 29 posts 49 karma points
    Dec 12, 2011 @ 23:38
    Peter Drayton
    0

    Does anyone have any ideas on how I can achiveve this?

    It's stumping me.

    I thought the solution I came up with would work.

    The admin backend work's a treat. Editor can pick which modules they want and the order (Using the uComponents Content Picker.

    I just can't display the Subscribe Form (ascx) User Control, as to display the Modules picked, I am using an xslt Macro.

    Will I have to write the entire Side Panel as an ascx Control?

    And here's me thinking Umbraco was a decent CMS? Achieved the same thing in Drupal in half the time :-(

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Dec 12, 2011 @ 23:44
    Bo Damgaard Mortensen
    0

    Hi Peter,

    Without sounding like an ol' grumpy man, I think it's a bit hurry to question the quality of Umbraco. I think you have to keep in mind that XSLT and an ASP.NET UserControl is two totally different things that should not be mixed up at best :-)

    I think it would be best to decide whether to use an ASP.NET UserControl or an XSLT file to do the job for you. If you really need to mix up the two things, you would be better off writing an XSLT extention in .NET that you can use in your XSLT file - at least that's what most of us do when a twist of .NET code is needed in our XSLT.

    Hope it makes sense :-)

    All the best,

    Bo

  • Peter Drayton 29 posts 49 karma points
    Dec 13, 2011 @ 17:29
    Peter Drayton
    0

    How do I go about writing the XSLT Extension?

    All I'm trying to do is use the Umbraco CMS to decide whether to display an .ascx or not based on an editor decision in the CMS.

  • Peter Drayton 29 posts 49 karma points
    Dec 13, 2011 @ 18:31
    Peter Drayton
    0

    Ok,

    I'm trying this a different way now,

    I have the following in a MasterPage:

          <umbraco:Macro Alias="SubscribeForm" runat="server" /> (This is an .ascx UserControl)
          <umbraco:Macro Alias="ListArchives" runat="server" /> (This is an xslt macro)
          <umbraco:Macro Alias="ModuleA" runat="server" /> (This is an xslt macro)
          <umbraco:Macro Alias="ModuleB" runat="server" /> (This is an xslt macro)

    How can I change whether or not to display the individual macros and the order they appear on the page based on a content of a Multi-Node Tree Picker?

    Anyone have any suggestions?

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 14, 2011 @ 10:39
    Chriztian Steinmeier
    0

    Hi Peter,

    Because Macros are self-contained units (and the whole render workflow they're part of) you can't trigger their rendering from e.g. a Multi-Node Tree Picker or similar.

    There is however, a datatype that will do just that: The "Macro Container" - the UI is not quite as polished as the MNTP but it gets the job done, and it works with any Macro type, be it XSLT, UserControl or (I believe) any of the scripting types...

    /Chriztian

  • Peter Drayton 29 posts 49 karma points
    Dec 14, 2011 @ 11:06
    Peter Drayton
    0

    Cheers Chriztian,

    Works like a treat! :-)

     

  • Peter Drayton 29 posts 49 karma points
    Dec 14, 2011 @ 11:48
    Peter Drayton
    0

    Is it possible to EDIT the text on the MacroContainer itself?

    i.e Where it says "Insert Macro", "Remove Macro" and "Macro:"?

Please Sign in or register to post replies

Write your reply to:

Draft