ModxI have been developing a new site with a directory component lately and thought I would document the technique I am using to create this effect. It primarily uses Ditto and a snippet comprised of if else statements.

Document Structure

  1. Level One
    • The Directory will be contained within a folder, lets say it’s in the root of the site. I usually place a [!FirstChildRedirect!] snippet call in the content area of this document. This document is just a container.
  2. Level Two
    • The first child within this folder is used for a landing page. The content area describes the content/purpose of the directory. You can also create a dropdown navigational aid using another Ditto call (I will describe at the end of this article). This page is not a folder.
    • The rest of the child documents below this first one are all folders. These containers are used as categories within the directory. If the end user wants to add a new category all they have to do is create a new directory and it’s contents.
  3. Level Three
    • The children in this level are the individual items of the directory. These are individual documents contained within the Level 2 folders, no more containers at this level.

Documents Structure and Fields

I place the Ditto calls within the template (actually within an if else snippet, see below). I then create all of my text fields as Template Variables. I also use ManagerManager snippet to hide any unused fields from the end user. That way all that is seen are the fields that are needed.

I chose the normal internal pages template for the landing page. That way the Ditto calls would not show up on this page. By using ManagerManger to hide the template selection field the user cannot change this template setting.

The Snippet(s)

I am assuming that you have some familiarity with the Ditto snippet used with MODx. What you may be realizing is that within this structure we are requiring two different Ditto calls. One if you are viewing a Level 2 directory and it’s child documents (Level 3). Another if you are directly viewing a Level 3 document.

To accomplish this I have created a snippet that is just a PHP if else statement (below) that uses the documentObject to determine if a folder is or is not present:

<?php
$Folder = $modx->documentObject['isfolder'];
if ($Folder=="1")
  $output="{{directoryFolder}}";
else
if ($Folder=="0")
 $output="{{directoryPages}}";
return "$output";
?>

Depending on whether or not the document is a folder a slightly different Ditto call within a chunk is called in.

This is the {{directoryFolder}} call:

[!Ditto? &startID=`[*id*]` &depth=`2` &tpl=`physicianTPL` &sortBy=`lastName` &sortDir=`asc` &summarize=`10` &paginate=`1` &paginateAlwaysShowLinks=`1`!]

and this is the {{directoryPages}} call:

[!Ditto? &documents=`[*id*]` &depth=`2` &tpl=`physicianTPL2` &summarize=`10` &paginate=`1` &paginateAlwaysShowLinks=`1`!]

Notice that I did use similiar, but slightly different TPLs here for layout. This was a personal choice, but I found that the Level2 and Level3 presentation of the same document required slightly different data presentation.

I do want to mention the TPL, placeholder structure here. It is possible to create a statement that calls in a field only when there is data present. In the example below I created a field to display a website link that display nothing if the field is left blank. All of the placeholders can be formatted in this way:

[+docLink:isnot=``:then=`<a href="[+docLink+]" title="[+pagetitle+]'s Website" target="_blank">[+pagetitle+]'s Website</a>`+]

The Dropdown Navigation

Once again I use Ditto to create another feature of the Directory. I created a chunk that uses a little JavaScript for a clickable dropdown menu:

<script language="JavaScript">
<!--
function goToNextPage()
{
PageIndex=document.form_menu.My_Choice.selectedIndex
if (document.form_menu.My_Choice.options[PageIndex].value != "none")
{
location = document.form_menu.My_Choice.options[PageIndex].value
}
}
-->
</script>
<form name="form_menu">
<select name="My_Choice" size="1" onchange="goToNextPage()">
<option value="none" selected="selected">WRHS Physicians</option>
[!Ditto? &startID=`6` &tpl=`dropdownTPL` &depth=`2` &sortBy=`lastName` &sortDir=`asc` &hideFolders=`1` &filter=`id,[*id*],2`!]
</select>
</form>

As you can see in my Ditto call I found it necessary to hide the categories (folders) and then used the filter to remove the landing page from the output.

The Wayfinder Navigation

As I put all of this together I have also used a Wayfinder call in to create a listing of all of the Level 2 directories in the sidebar of my site. Using this approach I am only displaying the categories (Level 2 folder) and not the category contents (Level 3 documents):

[!Wayfinder? &startId=`[[UltimateParent? &topLevel=`0`]]`&level=`1` &firstClass=`titleinteriornav`!]

By using all of the wonderful MODx tools at my disposal this approach has given me exactly the view(s) I need and allows an end user to create new categories without droping in any additional code or even changing templates (as I mentioned above, that field was hidden too). On their end I don’t know how this could be made any more straightforward for an end user.

  • http://www.groundswellmediaproductions.com/ Nathan Stephens

    Can you show me an example of how your directory turned out? I'd like to take a look at the site design. Thanks so much.

  • http://www.gregorysmart.com Gregory Smart
  • nolner

    Great article. Wonder if you can help with this problem? Having no success on modx forums:

    I want to provide a dropdown menu with the links to aggregated pages [+pages+] from ditto, with the page titles, using wayfinder – any ideas how to do this? It looked like tplPaginatePages was the way but can't get it to work… or is there a way to just change the link in wayfinder??

    To be clear (?!) I want a dropmenu with links to pages 1,2..etc but with the pagetitles of the aggregated docs, rather than the 1,2..

    Hope you can help! This should be easy I think, but can't see how!

    thx

  • http://www.gregorysmart.com Gregory Smart

    I might suggest using Ditto rather than Wayfinder to generate the dropdown menu code. Wayfinder is a great tool, but I find I tend to lean on Ditto to generate these types of menus with very specific output. I set up the TPL to generate the list items and the place the call within <ul> tags. Hope that helps.

  • nolner

    That sounds sensible as all I wanna do is provide the ditto links in a different format – but there seems to be no way to take those links as provided in {+pages+] and output them with different link text (pagetitle) – ie no way to template [+pages+] itself?

  • http://www.gregorysmart.com Gregory Smart

    Can you post the forum link? I would be interested in seeing what some of the other comments would be on this.

  • nolner
  • http://www.gregorysmart.com Gregory Smart

    I sent out a tweet about it with a link to the forum post and this RSS. Twitter is a pretty good place to get help like this too. Most of the people I follow are related to MODx, you can also search #modx.

  • nolner

    Lol, thx – never thought of using twitter for this stuff – but then I have follwers and have never sent a tweet!

    Heres another one you can maybe help with:
    http://modxcms.com/forums/index.php/topic,44132…

    thx again

  • Pingback: Ditto/PHx Directory w/Cross-Categorization | Greg Smart

  • http://www.cheap-nikeshox.com/nike-shox-R5-women.html shox nz

    Well , the view of the passage is totally correct ,your details is really reasonable and spring-bags.com you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!

  • Ross

    Just what I was looking for…great job.

  • http://www.nikeshox-outlet.com nike shox

    Thanks a lot for sharing. You have done a brilliant job. Your article is truly relevant to my study at this moment, and I am really happy I discovered your website. However, I would like to see more details about this topic. I’m going to keep coming back here.

  • http://www.nikeshox-outlet.com nike shox

    Interesting post, nice site have been looking at someof your other posts, will add you to my RSS feeds!

  • tino

    I am a bit of a newbie in Ditto though I have used other aspects of MODx.

    I followed through the article and created the templates and documents as advised. I thought I understood most of it.

    I do not understand the last item under the title “The Snippet(s)”. The one with the following

    code:

    [+docLink:isnot=``:then=`[+pagetitle+]'s Website`+]

    Here you started talking about placeholders yet in the beginning we created TVs. Is docLink some

    sort of plugin like pHX? or its a placeholder that relates/is converted from a TV you created(as

    one of the directory item fields)

    As an example:

    I created the following TVs to hold the field values:

    [*CompanyName*] - Text

    [*Email*] - Input Type: Email

    [*Website*] - Input Type: URL


    Then in the {{directoryFolder}} chunk, I had the following Ditto Call:

    [!Ditto? &startID=`[*id*]` &depth=`2` &tpl=`physicianTPL` &sortBy=`lastName` &sortDir=`asc` &summarize=`10` &paginate=`1` &paginateAlwaysShowLinks=`1`!]

    In my {{physicianTPL}} Chunk I have:

    Company Name:[+CompanyName:isnot=``:then=`[+CompanyName+]`+]

    Email:[+Email:isnot=``:then=`CompanyEmail`+]

    Website:[+Website:isnot=``:then=`[+pagetitle+]'s Website`+]

    It outputs 10 iterations of

    Company Name:

    Email:

    Website:

    …without and content.

    Note that I have only created ONE directory entry as a test and expected to see just that one.

    What have I done wrong? And why do we call placeholders e.g [+Website+] when we created TVs e.g.

    [*Website*]

    Hope you can help.

    My apologies for the very long email and the ignorance.

  • http://www.gregorysmart.com Gregory Smart

    In this example docLink is a Template Variable. This is a PHx statement, inside of a TPL, that checks to see if the TV is not blank. If it is not, then it renders the content inside of the ‘then’ statement. This keeps it from outputting anything unless there is something there to output.
    So, if I am understanding, in your TPL the PHx statements would look like: [+CompanyName:isnot=``:then=`Company Name:[+CompanyName+]`+]