Hi folks,
I’m new to MODx, but pretty familiar with PHP. I’m trying to put together a site with products and categories. I want each category page to show a list of the products within it. (The product pages will be contained in the category page/folder.) I’m using MODx 0.9.5 and Ditto 1.0.2.
Ditto lets me do this very easily. On the category page, I put this snippet:
[!Ditto? &startID=`[*id*]` &summarize=`5` &total=`20` &tpl=`dittochunk` &paginate=`1` &trunc=`1` &truncLen=`300` &displayArchive=`0` &paginateAlwaysShowLinks=`1` &descendentDepth=`1` &sortBy=`tvsoldstatus` &sortDir=`ASC` !]
My tpl chunk looks like this:
<tr>
<td>[+pagetitle+]</td>
<td>[*pagetitle*]</td>
<td>[+tvprice+]</td>
<td>[+tvdatelisted+]</td>
<td>[+tvsoldstatus+]</td>
<td>[+tvphoto1+]</td>
<td><a href="[~[+id+]~]">View Details</a></td>
</tr>
and on the category pages, I surround things with a table tag.
However, I’d like to be able to sort the table based on user input: if they click a column header in this table, I want to sort on that column. I can make the headers of the tables links, but am not quite sure where to go after that. If I were writing a normal PHP application, I’d switch on the value of $_REQUEST[’sortbycol’] and put that in the call to ditto:
[!Ditto? &startID=`[*id*]` &summarize=`5` &total=`20` &tpl=`dittochunk` &paginate=`1` &trunc=`1` &truncLen=`300` &displayArchive=`0` &paginateAlwaysShowLinks=`1` &descendentDepth=`1` &sortBy=`$_REQUEST['sortbycol']` &sortDir=`ASC` !]
That does not work. I also tried creating a separate chunk for each way I want to sort (the only differences between the following chunks is the sortBy parameter):
To sort on price (a chunk called sortdittobyprice):
[!Ditto? &startID=`[*id*]` &summarize=`5` &total=`20` &tpl=`dittochunk` &paginate=`1` &trunc=`1` &truncLen=`300` &displayArchive=`0` &paginateAlwaysShowLinks=`1` &descendentDepth=`1` &sortBy=`tvprice` &sortDir=`ASC` !]
To sort on name (a chunk called sortdittobyname):
[!Ditto? &startID=`[*id*]` &summarize=`5` &total=`20` &tpl=`dittochunk` &paginate=`1` &trunc=`1` &truncLen=`300` &displayArchive=`0` &paginateAlwaysShowLinks=`1` &descendentDepth=`1` &sortBy=`tvsoldstatus` &sortDir=`ASC` !]
And including this chunk via a snippet that looks at $_REQUEST and outputs the chunk (this was called by [!callDitto!]):
<?php
if ($_REQUEST['sortBy']) {
//$modx->putChunk('sortdittobyprice');
?>
{{sortdittobyprice}}
<?php
} else {
//$modx->putChunk('sortdittobyname');
?>
{{sortdittobyname}}
<?php
}
?>
As you can see, I tried the {{ notation as well as the putChunk call (I’m not sure whether putChunk is part of the API--it’s not here:
http://modxcms.com/api-quick-reference.html, but is here:
http://modxcms.com/chunks.html. Neither worked. The Ditto snippet that I expected to be parsed was not, and the output was always just:
[!Ditto? &startID=`[*id*]` &summarize=`5` &total=`20` &tpl=`dittochunk` &paginate=`1` &trunc=`1` &truncLen=`300` &displayArchive=`0` &paginateAlwaysShowLinks=`1` &descendentDepth=`1` &sortBy=`tvsoldstatus` &sortDir=`ASC` !]
What was weird is that when I didn’t have the callDitto snippet in the way, but just called one of the chunks directly, the Ditto snippet executed. I guess snippets can’t call other snippets?
Anyway, any suggestions on what to do would be welcome. I’m leery of using a template variable, because more than one user could be viewing this category page at one time. Perhaps I don’t understand template variables? Is there a more ’MODx’ way of doing things?
The other thing I’ve considered doing is changing the ditto source. I noted that some of the Ditto snippet looks at $_REQUEST. But I’d prefer not to make such a change if there’s a better way?
I’ve looked through the MODx forums, but haven’t really seen anything. I also browsed the Ditto documentation and the wiki.
Also, if Ditto isn’t the best way to do this, I’d appreciate any other advice. I saw the MakeTable snippet (
http://modxcms.com/MakeTable-622.html), but I’m planning to use TVs for my custom attributes (so I get all the control goodness) and MakeTable didn’t seem to work with anything other than a single DB table.
Thanks,
Dan