Mousetrap for template errors

  Previous article Next article  

Mousetrap for template errors

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.5
  Last updated: 13-01-2018
  Comments: 0
  http://cms.ms/AkHo

Sometimes 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 then 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.

mousetrap
$to = 'yourname@website.com';
$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:

{mousetrap url=$smarty.server.REQUEST_URI e_line=$e_line e_file=$e_file e_message=$e_message}

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.

send_message
$to = 'yourname@website.com';
$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:

{send_message url=$smarty.server.REQUEST_URI message='The name of the GCB is: somename'}



CMS Made Simple 2.2.5 - Tutorials, tips and tricks - CMSMS 2.2.5

Mousetrap for template errors

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.5
  Last updated: 13-01-2018
  Comments: 0
  http://cms.ms/AkHo