We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18266
    • 23 Posts
    Hi everybody

    Although already discussed earlier in http://modxcms.com/forums/index.php/topic,10151.msg69493.html#msg69493, I´d like to post the following issue again: I want to display the dynamically generated results of a Ditto call in two columns given by the page template, depending on the id (even/odd). Currently I have two approaches:

    Alternative 1:

    Decision about the position (left/right col) in the page template

    <div id="left_col">
    [+phx:if=`document id is odd`:then=`[!Ditto? etc.!]`:else=``+]
    </div>
    
    <div id="right_col">
    [+phx:if=`document id is even`:then=`[!Ditto? etc.!]`:else=``+]
    </div>


    A fixed order of the results like in http://www.modxcms.de/forum/comments.php?DiscussionID=237 (German) is not feasible in this case because the output is depending on various filter criteria.

    Here, I could need an idea how I can check the id of the selected documents if they are even or odd. IMO this is only possible within the Ditto call, because otherwise, for example with...

    <?php
    $id=$_GET['id'];
    etc.
    ?>


    ...I will only get the id of the current document.

    Alternative 2:

    Decision about the output within the Ditto template, whereas the position of the result is selected via the PHx-Modifier phx:leftright:

    a) Snippet
    <?php
    $leftright=$output % 2;
    return $leftright;
    ?>


    b)Template left column
    [+ditto_iteration:leftright:is=`0`:then=``:else=`
    <div id="address">
    <p>Result</p>
    </div>`+]


    c)Template right column
    [+ditto_iteration:leftright:is=`0`:then=`
    <div id="address">
    <p>Result</p>
    </div>`:else=``+]


    ... as in Marcs suggestion in http://www.modxcms.de/forum/comments.php?DiscussionID=755 (also German)

    Unfortunately, I do not get any results, i.e. an empty result page regardless of my filter criteria. Ditto 2.1.b3 is installed.

    Any suggestions?

    Thanks & regards!
      • 3749
      • 24,544 Posts
      I think alternative #2 is the way to go, but I think you need something like this (untested):

      [+ditto_iteration:[!leftright? &output=`[*id*]`!]:is=`0`:then=``:else=`
      <div id="address">
      <p>Result</p>
      </div>`+]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 23571
        • 223 Posts
        I realize I am not directly addressing the even and odd issue, but if you use &tplAlt you can alternate the output like below:
        [!Ditto? &startID=`0` &tpl=`navTPL` &tplAlt=`navTPL2`!]

        wherenavTPL is:
        <dt> 
        <a href="[~[+id+]~]" title="[+pagetitle+]">[+pagetitle+]</a>
        </dt>

        and navTPL2 is:
        <dd> 
        <a href="[~[+id+]~]" title="[+pagetitle+]">[+pagetitle+]</a>
        </dd>

        Hope that helps.
          • 18266
          • 23 Posts
          Heureka!

          Gregs approach is surely an option, but I chose the follwing way:

          1) Ditto template, you need only one
          <div id="address" class="[+ditto_iteration:leftright+]">
          <p>Dynamically generated filter result</p>
          </div>


          2) PHx-Modifier (as a snippet named [[phx:leftright]])
          <?php
          if ($output % 2) {
                return 'right';
                } else {
                return 'left';
                }
          // See also http://wiki.modxcms.com/index.php/PHx/CustomModifiers#phx:evenodd
          ?>


          3) CSS-Classes for left & right
            .left, .right {width: 50%}
            .left{float: left;}
            .right{float: right;}


          ... and you´re done!

          Live long & prosper!
          Marcus
            • 3749
            • 24,544 Posts
            Looks good. Glad you got it sorted. smiley
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting