Page 1 of 1

a problem with adding PHP to template with UDT

Posted: Thu May 29, 2025 9:26 pm
by offsidetrap
Hello all, I wonder if you could help me.

I am trying to add some PHP to my template using a UDT but when I submit I just see a blank white page. The blank page loaded is editusertag.php

There is quite a lot of PHP code but through trial and error I have managed to narrow down the problem to these 2 lines (edited slightly for privacy reasons):

require 'path-to-file.php';
use class\CLASS;

There is no error shown on screen or in browser dev tools, any ideas would be greatly appreciated.

Re: a problem with adding PHP to template with UDT

Posted: Thu May 29, 2025 11:09 pm
by DIGI3
There is a bug in the current version where it processes the submitted code instead of just verifying it, so any PHP errors in your code or anything not parsable in admin will cause it to white screen on submit.

Best option for now is to use a plugin instead of a UDT - then you should only get errors on the page you call it on. See /lib/plugins/ for examples, and put yours in /assets/plugins.

Re: a problem with adding PHP to template with UDT

Posted: Wed Jun 04, 2025 8:50 pm
by webform
My work around to handle the bug in UDT, is to create the UDT with only a PHP comment and then submit the full PHP code in the cms_userplugins table in phpMyAdmin.
Just remember to Clear Cache in System Maintenance after submitting the PHP code, so the UDT loads the code.

Re: a problem with adding PHP to template with UDT

Posted: Thu Jun 05, 2025 9:36 am
by creopard
just for reference: https://dev.cmsmadesimple.org/bug/view/12749

This bug has already been fixed in the trunk, hasn't it?
file \admin\editusertag.php line 98

instead of

Code: Select all

    try
    {
      eval($code);
      ob_get_clean();
    };
it's now:

Code: Select all

    try
    {
      # let's try to eval the code but not execute it
      $tmp = 'return;' . $code;
      eval($tmp);
      ob_get_clean();
    }