On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I have a problem to make document output by alphabet. Letter buttons must be active only in case the documents are on this letter filter.

    Header buttons: ALL | A | B | C | D | ... | Z

    -----
    Document tree

    Makers (49)
    Maker1
    Maker2
    ...
    ABC (109)
    A
    B
    C
    ...
    Z

    Template
    -----
    <!-- Header
    <ul class="abecele">
    <li><a href="[~[*id*]~]">ALL</a></li>
    [!Ditto? &id=`abc` &parents=`109` &tpl=`abecele` &sortBy=`pagetitle` &sortDir=`ASC`!]
    </ul> -->

    <!--Catalog output
    <ul class="abecele">
    [[Ditto? &parents=`49` &tpl=`makers` &sortBy=`pagetitle` &sortDir=`ASC` &paginate=`1` &extenders=`request` ]]
    </ul> -->
    -----

    Chunk - "abecele"
    <li><a href="[~[*id*]~]&ditto_filter=lastname,[+pagetitle+],11">[+pagetitle+]</a></li>

    Chunk - "makers"
    <li><a href="[~[+id+]~]">[+lastname+] [+name+]</a></li>

    -----

    All works except active and inactive alphabet button links.
    I’ve tried to make "abecele" chunk:
    [+phx:if=`[+total+]`:is=`0`:then=`<li>[+pagetitle+]</li>`:else=`<li><a href="[~[*id*]~]&ditto_filter=lastname,[+pagetitle+],11">[+pagetitle+]</a></li>`+]


    But it doesn’t work, any suggestions?
    • The following is a comprehensive tutorial how to build letter index with active/inactive letter-buttons depending on actual presence of documents in container(s) being the subject of interest/search.

      Prerequisites are three chunks, for example, named: "empty", "one-letter", and "index".

      "empty" chunk is used for generating empty output -- its content should be something like:
      [+none+]
      

      where [+none+] stands for non-existent TV name which, at a runtime, will be replaced by Ditto with empty text.

      "one-letter" chunk is used for generating listing of documents whose filtered TV (lastname in the above-post) starts with specific letter, its sample content might be as follows:
      <li><a href="[~[+id+]~]">[+lastname+]</a></li>
      


      "index" is used for generating A B C... Z active/inactive buttons, I will build its content at the end.

      You need to put into content field of each A, B, C, ..., Z document Ditto call:
      <ul>[[Ditto? &parents=`49` &depth=`1` &display=`all` &tpl=`one-letter` &noResults=`empty` &filter=`lastname,[*pagetitle*],11` &sortBy=`lastname` &sortDir=`ASC`]]</ul>
      


      Next you need to build A B C ... Z index in your ABC document; for this purpose place into the content of this doc the following Ditto call:
      <!-- manually build ALL link here -->
      [[Ditto? &parents=`109` &depth=`1` &display=`all` &tpl=`index` &sortBy=`pagetitle` &sortDir=`ASC`]]
      


      And finally, "index" chunk, the most sophisticated part of this task:
      [+phx:if=`[[Ditto? &parents=`49` &depth=`1` &tpl=`one-letter` &noResults=`empty` &filter=`lastname,[+pagetitle+],11`]]`:is=``:then=`[+pagetitle+]`:else=`<a href="[~[+id+]~]">[+pagetitle+]</a>`+]
      

      Of course, the above only looks like a sophisticated thing, but actually it is a simple if-then-else statement expressed in PHx terms. Before building each letter-button in the index, you need to check whether documents starting from this letter exist or not. This part is performed by if-part of PHx. If Ditto returns no output (there are no documents), then the letter as a static text is rendered (then-part of PHx). Otherwise (else-part of PHx), linked letter is rendered. Done.
      The advantage of this solution is that it requires neither extender nor ugly-looking url stuff.

      Edit: this was a long post so some inconsistencies appeared in it, but hope I removed them all.
      • Thx man, respect!!!
        For this moment there was no any working solutions (snippets or plugins) for this task, but now it is.
        • Hi Labasus,
          nice to hear that it works for you. Please mark the thread as "solved" or so thus signaling for others that it comprises working solution.
          (In my spare time, I will copy document structure from your post and put this tutorial onto my site where I am collecting the most interesting solutions provided to this forum.)
          • Hey alik,

            thanks for the how-to!
            For this moment there was no any working solutions (snippets or plugins) for this task, but now it is.
            ...would the a2z Snippet be an alternative for this? http://modxcms.com/forums/index.php/topic,36667.msg221349.html#msg221349