MENU

Mousetrap for template errors

  Previous article Next article  

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

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'}

Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  2 Comments

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Mousetrap for template errors

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.5
  Last updated: 28-10-2021
  Comments: 2
  http://cms.ms/AkHo


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!