Mark Your Debug Messages
When developing a Perch site, it’s helpful to turn on Debug Mode.
The debug message displays various information such as SQL queries (and how long they take), templates used (or if not found) and routes matched (if you’re using Runway).
You can output to the debug message, similar to how you’d output to the browser’s console with Javascript’s console.log()
, except this is highlighted for you and easy to spot.
PerchUtil::mark('Some message');
How is this useful?
When you’re working on complex pages the debug message can get a bit long. It can be useful to mark the start and end of certain calls to check what’s going on.
For instance, the following will output a highlighted message right before and immediately after the debug messages related to perch_shop_products()
.
PerchUtil::mark('Start: Products listing');
perch_shop_products([
'template' => 'products/list.html',
'count' => 15,
]);
PerchUtil::mark('End: Products listing');
Your list.html
template may have a Layout include too:
<perch:layout path="shop/footer">
And you may be making more database queries from the Layout, so you can also use PerchUtil::mark()
in there too to help you spot any issues that may originate from there.