I could be wrong, but I think there are two separate ways to go and you’re kind of going in both directions at once.
1. Have a separate resource for each house with TVs for the sq feet, br’s, path to image, etc. The data is stored in the TV’s, no snippet necessary except for searching, and getResources should be able to do it either out-of-the-box, or with a custom filter.
2. (This is much more efficient and is definitely the way to go if you’ll have a lot of houses and/or a lot of visitors to the site).
- Keep *all* the data for each house in a custom DB table (preferably set up to work with xPDO), with one row for each house.
- In your snippet, which can be on the search page activating only on submission:
- Query the DB based on the search form
- If there are no results, get the "No Results" Tpl Chunk and return it.
- Get the "House" Tpl chunk with $modx->getChunk()
- Iterate through the results, using str_replace() to replace the placeholders in the chunk, adding the result to the $output variable.
- return the $output.
That part of the snippet would look something like this (I’m using an xPDO example where each house is an xPDO object -- easier than it looks):
<?php
/* test for postback status here */
$output = $modx->getChunk('SearchHeaderTpl'); // Anything you want at the top of the results page.
// Might have placeholders for the search criteria
// e.g., "you searched for: 3+ BR, etc.
if ($isPostback) {
/* query the DB with getCollection() based on the search criteria set in $c */
$houses = $modx->getCollection('modHouse',$c);
if (empty($houses) ) {
$output .= $modx->getChunk('NoResultsTpl');
} else {
$tpl = $modx->getChunk('houseTpl');
foreach ($houses as $house) {
$tpl = str_replace('[[+squareft]]', $house->get('squareft'), $tpl);
$tpl = str_replace('[[+bedrooms]]', $house->get('bedrooms'), $tpl);
/* etc. */
$output .= $tpl;
}
}
return $output;
}
}