Blog Sections Open
Using a Custom where Clause in Ditto Safely
Ditto can be pushed far with custom filtering, including date-range logic through a handcrafted where clause. The original example used template variable values and request parameters to build a date filter. Example Shap
Ditto can be pushed far with custom filtering, including date-range logic through a handcrafted where clause. The original example used template variable values and request parameters to build a date filter.
Example Shape
if (isset($_GET['date']) && !empty($_GET['date'])) {
'@SQL: AND sc.id IN (
SELECT g.contentid
FROM modx_site_tmplvar_contentvalues AS g
WHERE g.tmplvarid = "23"
AND sc.id = g.contentid
AND g.value >= "' . $_GET['date'] . '"
)
AND sc.id IN (
SELECT m.contentid
FROM modx_site_tmplvar_contentvalues AS m
WHERE m.tmplvarid = "23"
AND sc.id = m.contentid
AND g.value <= "' . $_GET['date2'] . '"
)';
}
Main Warning
This kind of pattern is powerful, but raw request values should never be trusted blindly. Validate and normalize them before they enter SQL-oriented filter strings.
When It Is Worth It
Use this approach when the business logic is real and the dataset justifies it. If not, simpler filtered lists are easier to maintain and safer to debug.
Building a Clean HTML Sitemap from a Sitemap TV or XML Source
How to think about HTML sitemap pages when the site already has XML sitemap data or a sitemap TV-based source.
Running Shopkeeper with YAMS on a Three-Language Site
A practical overview of the extra care needed when Shopkeeper and YAMS are used together in a multilingual Evolution CMS store.