Copied to clipboard

Flag this post as spam?

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


  • Mikkel Johansen 116 posts 292 karma points
    Apr 23, 2010 @ 01:01
    Mikkel Johansen
    0

    Macro/xslt - rendering depending on used template

    Okay let me try and explain. Hope it makes sense.

    In the editor I will insert an macro, for example "Current Weather" that gets the current weather from a location set by a macro parameter.

    I then need to have two types of final output/templates: Fancy and Text.

    Right now I am thinking of making two templates:

    - Fancy: Super-cool weather status with graphics (clouds, sun, rain etc.)

    - Text: Example - Sunny, 24 C

     

    URLs with alternative templates

    .../weather/fancy.aspx
    .../weather/text.aspx

     

    How do I in the macro/xslt test wich template is in use ?

    Or should I do it in another way ?

     

    Thanks in advance
    Mikkel

  • Mikkel Johansen 116 posts 292 karma points
    Apr 23, 2010 @ 08:21
  • Tobias Neugebauer 52 posts 93 karma points
    Apr 23, 2010 @ 09:16
    Tobias Neugebauer
    0

    Hi,

    since you only specify the page wether in your cms calls to

    .../weather/fancy.aspx
    .../weather/text.aspx

    are the same as calls to

    .../weather.aspx?alttemplate=fancy
    .../weather.aspx?alttemplate=text

    If that is correct you could simply query for that alttemplate (in both cases) in your Xslt File like this: umbraco.library:HttpItem('altTemplate') and then create a xslt:when to determine which template is used.

    The umbraco requestHandler takes care of checking if there is a template specified in your url and then adds this to the HttpContext.Items which you can access through the library function HttpItem.

    Hope this helps

    Toby

     

     

  • Tobias Neugebauer 52 posts 93 karma points
    Apr 23, 2010 @ 09:39
    Tobias Neugebauer
    0

    I'm sorry the library Function is called GetHttpItem so this should give you the correct results:

      <xsl:choose>
        <xsl:when test="umbraco.library:GetHttpItem('altTemplate') = 'fancy'">
          <!--
            Do your fancy rendering
          -->
        </xsl:when>
        <xsl:when test="umbraco.library:GetHttpItem('altTemplate') = 'text'">
          <!--
            Do your text rendering
          -->
        </xsl:when>
        <xsl:otherwise>
          <!--
            Do nothing
          -->
        </xsl:otherwise>
      </xsl:choose>

  • Mikkel Johansen 116 posts 292 karma points
    Apr 23, 2010 @ 09:41
    Mikkel Johansen
    0

    Thanks Toby

    I will try it, and I all-ready believe that it will do the job.

    -Mikkel

Please Sign in or register to post replies

Write your reply to:

Draft