Mousetrap for template errors
Previous article Next articleSometimes difficult problems have simple solutions. I noticed in the adminlog of one of my CMS Made Simple™ websites some template errors have occurred, but I didn't know where exactly... Well, just browse the pages and search for the broken page you would say. But this is easier said than done, it is a huge website with almost 4000 blog articles. No way I could solve it this way.
I created a mail User Defined Tag, a few lines of PHP code sending out an Email to a preset mail address. The content of the mail contains the URL of the broken page and the error message. Call the UDT with parameters in the CMSMS error console template and the trap is set!
Now I can just sit and wait, because the UDT does the work for me!
How to use
Create a new User Defined Tag (UDT) "mousetrap" with the following content. Change the names and mail addresses to your own.
$subject = 'Error Website.com';
$url = isset($params['url']) ? $params['url'] : '';
$e_line = isset($params['e_line']) ? $params['e_line'] : '';
$e_file = isset($params['e_file']) ? $params['e_file'] : '';
$e_message = isset($params['e_message']) ? $params['e_message'] : '';
$message = 'An error has occurred at page: ' . $url . "\r\nProblem found in line ". $e_line . 'of file ' . $e_file . "\r\nThe error message is: " . $e_message;
@mail($to, $subject, $message);
Open in cPanel, Plesk or with your FTP program the template file /lib/assets/templates/cmsms-error-console.tpl and add in the bottom of the file the tag:
Note: This change will be overwritten when you upgrade the website! Because I see this tag as a temporary tool to detect and fix problems, I don't think it is a problem.
Working example
You can test it by creating an error in a page or news article.
For example add a non-existent tag {blahblah} in the content and open the page. You should get a mail with the url of that page and the error message.
Another example to use this method, finding a GCB at your website.
How to use
Create a new User Defined Tag (UDT) "send_message" with the following content. Change the names and mail addresses to your own.
$subject = 'Message from Website.com';
$url = isset($params['url']) ? $params['url'] : '';
$message = isset($params['message']) ? $params['message'] : '';
$the_message = 'Page: ' . $url . "\r\nMessage: " . $message;
@mail($to, $subject, $the_message);
Put in the content of your Global Content Block:
Comment Form
ReviewManager
ReviewManager
2 Comments
This post is really helpful, has helped me a lot.
Finds the smallest errors, that isn't always logged to php log.
Just wanted to say thanks for this. We are having issues with our CMS and this has really helped us to monitor them.