We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39501
    • 163 Posts
    I'm looking for a way to hook into the first or last child when using SiblingNav for templating purposes.

    I have 2 divs with a width of 50% each. If the first or last child displays, 50% of the remaining width is blank.

    This is my code:
    [[!siblingNav? &nextTpl=`tpl.sn.next` &prevTpl=`tpl.sn.prev`]]
                <section class="layout_routing layout_2col">
    [[+sn.prev]]
    [[+sn.next]]
                </section>
    
    
    


    In a perfect world, if the first or last child is displayed, .layout_2col would be removed from my template. Otherwise, if there was a previous and a next div, .layout_2col would be added back to my markup.

    I've tried using output modifiers on sn.prev and sn.next which was close, but not solid enough.

    Perhaps i'm over looking this...Has anybody come across this before or can suggest a solution?

    This question has been answered by Jako. See the first response.

    [ed. note: jonleverrier last edited this post 9 years, 6 months ago.]
    • discuss.answer
      Should be something like this, if sn.prev/sn.next are empty on the first/last page:

      <section class="layout_routing [[+sn.prev:ne=``:and:if=`[[+sn.prev]]`:ne=``:then=`layout_2col`]]">


      Hope sn.prev placeholder is set if it is empty. Otherwise something like this:

      <section class="layout_routing [[*id:if=`[[+sn.prev]]`:ne=``:and:if=`[[+sn.prev]]`:ne=``:then=`layout_2col`]]">
      [ed. note: Jako last edited this post 9 years, 6 months ago.]
        • 4172
        • 5,888 Posts
        not sure, if this will work, its untested

        snippet IfOneIsEmpty:

        <?php
        
        $then = $modx->getOption('then', $scriptProperties, '');
        $else = $modx->getOption('else', $scriptProperties, '');
        
        unset($scriptProperties['then']);
        unset($scriptProperties['else']);
        
        foreach ($scriptProperties as $value) {
            if ($value == '') {
                return $then;
            }
        }
        
        return $else;
        


        [[IfOneIsEmpty?
        &subject1 = `[[+sn.prev]]`
        &subject2 = `[[+sn.next]]`
        &then=``
        &else=`layout_2col`]]


        I think you should call both siblingNav and IfOneIsEmpty cached
        If not, call both uncached

        [Edit]
        I think, Jako's solution should also work.
        He is output-filter - King
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 39501
          • 163 Posts
          Jako & Bruno17 - Some solid solutions there, thanks for sharing.

          I managed to get it working with this and adjusting my CSS (not a great solution):
          <section class="layout_routing layout_2col [[+sn.prev:notempty=`col_left_active`]] [[+sn.next:notempty=`col_right_active`]]">
          


          However, i'm going to revert back and use Jako's idea as this is what I was after.

          Thanks again guys.