Mousetrap for template errors

  Previous article Next article  

Mousetrap for template errors

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.4
  Last updated: 31-07-2016
  Comments: 1

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 let alone over 2000 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 with your FTP program the template file /lib/assets/templates/cmsms-error-console.tpl and add in bottom, just under </html> the tag:

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

Note: This change can be overwritten when you upgrade the website! Because I see this tag as a temporary tool to 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.


A2 Webhosting CMS Made Simple

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

A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  1 Comment

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

Mousetrap for template errors

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.4
  Last updated: 31-07-2016
  Comments: 1

A2 Webhosting CMS Made Simple