We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 356
    • 31 Posts
    The problem I face is something really rarely for today CSS-based sites, but in my case I need to solve it in my particular case.

    Say I have a template that should display items from the first level of site tree in a table, like this:

    for site tree of
    - (root)
    -- text1
    -- text2
    -- text3
    -- text4

    the html template should be

    <table width="100%" ...>
    <tr>
    <td width="25%"><a href="link1">text1</a></td>
    <td width="25%"><a href="link2">text2</a></td>
    <td width="25%"><a href="link3">text3</a></td>
    <td width="25%"><a href="link4">text4</a></td>
    </tr>
    </table>

    The problem is that I can not recalculate "width" value depending on number of menu elements. The only solution I see is to create something like snippet that will do some SQL requests (select count(*) from modx_content where ....) and call it in the template, but that’s look like too heavy solution. Maybe there can be other way to archive that?

    The idea I have is to produce horizontal menu of 100% width that have equal sized cells for links. In fact, I try to convert old site that was made in pure html into modx-driven one, but I won’t change the design or look of it.

    Thank you in advance!
      • 3707
      • 241 Posts
      If you used Ditto to generate the table, you can use the [+total+] placeholder plus some PHx math to calculate the width. For example, place your Ditto call within a table wrapper:
      <table width="100%">
      <tr>
      [[Ditto? &tpl=`cellTpl` &paginate=`1`]]
      </tr>
      </table>

      The &paginate=`1` is required to populate the [+total+] placeholder.

      Then output the table cells to the cellTpl chunk using some math on the total to calculate the width:
      <td width="[+total:math=`100/?`+]"><a href="[~[+id+]~]">[+pagetitle+]</a></td>

      If you wanted to limit the width value to two decimal places, you could also use phx:price_format custom modifier to do that:
      <td width="[+total:math=`100/?`:price_format+]"><a href="[~[+id+]~]">[+pagetitle+]</a></td>
        • 356
        • 31 Posts
        Thank you, bob1000. I’ll try to do that the way you mentioned.

        Are there any manuals I can read on these math "secrets"? Looks like I missed that simple because didn’t know where to look for sad
          • 20413
          • 2,877 Posts
          That is a cool solution! cool

          http://wiki.modxcms.com/index.php/PHx
          http://wiki.modxcms.com/index.php/PHx/CustomModifiers

          PHx is built in the tpl’s for Ditto, Jot and some other snippets.
          If you want to use it site wide you need to install the plugin

          More...
          http://modxcms.com/forums/index.php/topic,33316.msg238447.html#msg238447 PHx Plugin 2.1.4 !!
          http://modxcms.com/forums/index.php/topic,34522.msg210035.html#msg210035
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower