Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 28, 2012 @ 17:49
    Bjarne Fyrstenborg
    0

    Different box templates

    Hi..

    I'm trying to set up a way to pick boxes with uComponents multinode-picker, but where the boxes should be different on frontpage than other pages.

    I have this in my xslt, which works fine with the multinode-picker:

    <xsl:param name="currentPage"/>
    <xsl:variable name="boxIds" select="$currentPage/ancestor-or-self::* [@isDoc and boxes != ''][1]/boxes//nodeId" />

    <xsl:template match="/">
      <xsl:if test="$boxIds != ''"> 
        <div class="boxList"> 
          <xsl:for-each select="$boxIds">
            
            <xsl:variable name="box" select="umbraco.library:GetXmlNodeById(.)" />
            <xsl:variable name="firstitem" select="position() = 1"/>
            <xsl:variable name="lastitem" select="position() = count($boxIds)"/>

            <xsl:variable name="className">
              <!--<xsl:text>sidebox</xsl:text>-->
              <xsl:if test="$firstitem = '1'"><xsl:textfirstitem</xsl:text></xsl:if>
              <xsl:if test="$lastitem = '1'"><xsl:textlastitem</xsl:text></xsl:if>
            </xsl:variable>
            
            <div>
              <xsl:if test="$className != ''">
                <xsl:attribute name="class">
                  <xsl:value-of select="$className" />
                </xsl:attribute>
              </xsl:if>
              
              <!-- Applying templates on the different boxes -->
              <xsl:apply-templates select="$box" />   
            </div>
          </xsl:for-each>
        </div>
      </xsl:if>
    </xsl:template>
        
    <xsl:template match="Box">
    <section class="sidebox">
      <xsl:if test="umbHeadline != ''">
        <h3><xsl:value-of select="umbHeadline" /></h3>
      </xsl:if>
      <xsl:value-of select="bodyText" disable-output-escaping="yes"/>
    </section>
    </xsl:template>
        
    <xsl:template match="BoxFrontpage">
    <div class="box">
      <xsl:variable name="image" select="./boxImage/DAMP/mediaItem[1]/*" />
      <img src="{$image/umbracoFile}" alt="" />
      <xsl:if test="umbHeadline != ''">
        <div class="boxTitle"><xsl:value-of select="umbHeadline" /></div>
      </xsl:if>
    </div>
    </xsl:template>

    Now I want to add classes for the columns, but Box template should have 1 column and BoxFrontpage 3 columns..

    How can I include something like this in the for-each, a specify the numbers on column in each template:

    <xsl:variable name="numberOfColumns" select="3" />
    <xsl:variable name="colcount" select="((position() + ($numberOfColumns - 1)) mod $numberOfColumns) + 1" />
    <xsl:attribute name="class">
    <xsl:textcol</xsl:text>
    <xsl:value-of select="$colcount"/>
    </xsl:attribute>

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 29, 2012 @ 22:09
    Chriztian Steinmeier
    0

    Hi Bjarne,

    Where do you need to set the additional col1/col3 class? Is it on the same <div> you're also setting $classname (firstitem/lastitem) ?

    /Chriztian

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 29, 2012 @ 22:22
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    I want to set the additional class like this:

    <section class="sidebox col1">
    ....
    </section>
    
    <div class="box col3">
    ....
    </div>

    but I think the count need to be inside the for-each, otherwise it always return col1 ...

    it's okay with the surrounding div and set a class for first and lastitem.. but I need to separate the elements and content from the two types of boxes.

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 29, 2012 @ 22:47
    Chriztian Steinmeier
    0

    Hi Bjarne,

    Alright - you're right about position() being 1 everytime inside the templates (the way they're used here).

    You can just send position() in as a parameter - like this:

    <xsl:apply-templates select="$box">
        <xsl:with-param name="pos" select="position()" />
    </xsl:apply-templates>

    And then add a <xsl:param name="pos" /> inside each of the templates.

    BTW: There's a last() function too - so you're className variable can be created a litttle simpler using that:

    <xsl:variable name="className">
        <xsl:if test="position() = 1"><xsl:text> firstitem</xsl:text></xsl:if>
        <xsl:if test="position() = last()"><xsl:text> lastitem</xsl:text></xsl:if>
    </xsl:variable>

    /Chriztian 

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 29, 2012 @ 23:04
    Bjarne Fyrstenborg
    0

    Okay, but it's okay that the classes firstitem and lastitem is set on the div container inside the for-each..

    More important is that the variables numberOfColumns and colcount is set inside the for-each.. and then the class is set in the templates..

    Should it be something like this:

    <xsl:apply-templates select="$box">
    
        <xsl:with-param name="numberOfColumns" select="3" />
        <xsl:with-param name="colcount" select="((position() + ($numberOfColumns - 1)) mod $numberOfColumns) + 1" />
        <xsl:attribute name="class">
                <xsl:text> col</xsl:text>
                <xsl:value-of select="$colcount"/>
        </xsl:attribute>
        </xsl:with-param>
    
    </xsl:apply-templates>

     

    and then add <xsl:param name="numberOfColumns" /> and <xsl:param name="colcount" /> inside each template?
    So I want to access the numberOfColumns and colcount values, where the class is added inside the templates. 

    /Bjarne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 30, 2012 @ 18:56
    Bjarne Fyrstenborg
    0

    You can see the frontpage boxes here: http://gittehoumand.dk.nt2.unoeuro-server.com/da/forside.aspx (Stress, Life ... ) and different sidebar box here: http://gittehoumand.dk.nt2.unoeuro-server.com/da/ydelser.aspx (Dagens ord, Ethvert godt samarbejde, Dagens inspiration)..

    So the same xslt file is used and on frontpage the administrator can pick some box types with uComponents multinode tree-picker and the same with the sidebar boxes..

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 30, 2012 @ 22:35
    Chriztian Steinmeier
    1

    Hi Bjarne,

    I threw this together to show how you send the position() value along to the templates and then further into a separate calculations template:

    <xsl:param name="currentPage"/>
    <xsl:variable name="boxIds" select="$currentPage/ancestor-or-self::*[normalize-space(boxes)][1]/boxes//nodeId" />
    
    <xsl:template match="/">
        <xsl:if test="normalize-space($boxIds)"> 
            <div class="boxList"> 
                <xsl:for-each select="$boxIds">
                    <xsl:variable name="box" select="umbraco.library:GetXmlNodeById(.)" />
                    <xsl:variable name="className">
                        <xsl:if test="position() = 1"><xsl:text> firstitem</xsl:text></xsl:if>
                        <xsl:if test="position() = last()"><xsl:text> lastitem</xsl:text></xsl:if>
                    </xsl:variable>
    
                    <div>
                        <xsl:if test="normalize-space($className)">
                            <xsl:attribute name="class">
                                <xsl:value-of select="$className" />
                            </xsl:attribute>
                        </xsl:if>
    
                        <!-- Applying templates on the different boxes -->
                        <xsl:apply-templates select="$box">
                            <xsl:with-param name="pos" select="position()" />
                        </xsl:apply-templates>
                    </div>
                </xsl:for-each>
            </div>
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="Box">
        <xsl:param name="pos" />
        <section>
            <xsl:attribute name="class">
                <xsl:text>sidebox </xsl:text>
                <xsl:call-template name="column-calc">
                    <xsl:with-param name="pos" select="$pos" />
                </xsl:call-template>
            </xsl:attribute>
            <xsl:if test="normalize-space(umbHeadline)">
                <h3><xsl:value-of select="umbHeadline" /></h3>
            </xsl:if>
            <xsl:value-of select="bodyText" disable-output-escaping="yes"/>
        </section>
    </xsl:template>
    
    <xsl:template match="BoxFrontpage">
        <xsl:param name="pos" />
        <div>
            <xsl:attribute name="class">
                <xsl:text>box </xsl:text>
                <xsl:call-template name="column-calc">
                    <xsl:with-param name="pos" select="$pos" />
                    <xsl:with-param name="numberOfColumns" select="3" />
                </xsl:call-template>
            </xsl:attribute>
    
            <xsl:variable name="image" select="boxImage/DAMP/mediaItem[1]/*" />
            <img src="{$image/umbracoFile}" alt="" />
            <xsl:if test="normalize-space(umbHeadline)">
                <div class="boxTitle"><xsl:value-of select="umbHeadline" /></div>
            </xsl:if>
        </div>
    </xsl:template>
    
    <xsl:template name="column-calc">
        <xsl:param name="numberOfColumns" select="1" /><!-- Default to one column -->
        <xsl:param name="pos" />
        <!-- Calculate value -->
        <xsl:variable name="colcount" select="(($pos + ($numberOfColumns - 1)) mod $numberOfColumns) + 1" />
        <!-- Output classname -->
        <xsl:value-of select="concat('col', $colcount)" />
    </xsl:template>

    /Chriztian

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 30, 2012 @ 23:44
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    Now it makes sence to me :)
    So in BoxFrontpage you set the numberOfColumns parameter to 3.. and in Box where it isn't set, it will fallback to 1 which is set inside column-calc template?

    It now works as intended..

    Thanks for your help :)

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 30, 2012 @ 23:46
    Chriztian Steinmeier
    0

    Hi Bjarne,

    Yes, that's exactly how it works :-)

    /Chriztian

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 31, 2012 @ 18:18
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    It's awesome using templates instead of creating two xslt-files for this.. :)

    Perhaps you have an answer on this question related to the boxes:
    A have created a parent node for Sidebar boxes and a parent node for Frontpage boxes.. and then the boxes as children of these nodes. On fronpage and the other page nodes I then pick the box nodes with multi node tree-picker

    If I have a box "Daglig Inspiration" on this page: http://gittehoumand.dk.nt2.unoeuro-server.com/da/ydelser.aspx and want the content in this box to be different on another page, how could this be done?

    Of course I can just created on new box node similar to the other "Daglig Inspiration" node and add different content.

    Or do you have a suggestion on this? 

    /Bjarne

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 31, 2012 @ 19:12
    Chriztian Steinmeier
    0

    Hi Bjarne,

    I'm not sure I fully understand the question, but here's how I'd handle it:

    1. I'd create a Multi-Node Tree Picker property called dagligInspiration on all the Document Types that should be allowed to pick content for it.

    2. In the XSLT I'd use my MultiPicker Helper to render the content.

    (There is no step three :-)

    /Chriztian

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 31, 2012 @ 21:18
    Bjarne Fyrstenborg
    0

    Hi Chriztian

    I have this content structure.

    I was thinking the easiest way may be to create a children of e.g. "Daglig inspiration" for each variants of the box.. so it's possible to pick to children instead..
    then children can use same doctype and therefore have the same properties to use..

    /Bjarne 

Please Sign in or register to post replies

Write your reply to:

Draft