500 Internal Server Error - Can't find function [9.x] [PHP7.4]

Got website which I constantly update from 8.5x. to 9.1.2 and always encunter some issues. Now got error 500 in case where I try to change design/block template. Its just does not work. Earlier (I dont remember but think about 9.1) worked, at least when I putted new block and was able to change template BUT after that I can’t. Now even not work change template on new block.
I can’t reproduce this error on fresh install since there simply works.

In my case in EDITMODE seems like loaded in header functions by View::element(‘file.php’) not loaded when throw me error about not found function. Files live in ./application/elements/ .

I have no idea how can I fix it. Of’coz website works and those issues I have only when enter edit-mode.

error	Object { type: "Error", message: "Call to undefined function showEditMode()", code: 0, … }
type	"Error"
message	"Call to undefined function showEditMode()"
code	0
file	"/home/***/domains/***.pl/public_html/application/blocks/page_list/templates/uc_ongrid_list.php"
line	12
trace	[ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
errors	[ "Call to undefined function showEditMode()" ]
0	"Call to undefined function showEditMode()"

And throwed error:

https://www.***.pl/index.php/ccm/system/dialogs/block/design?cID=208&arHandle=Main&arGridMaximumColumns=&arEnableGridContainer=1&aID=97&bID=186
500 Internal Server Error
WersjaHTTP/3
Sent 2,33 KB (32,48 KB)
strict-origin-when-cross-origin
Highest

    	
    cache-control
    	public
    content-encoding
    	br
    content-type
    	application/json; charset=UTF-8
    date
    	Thu, 29 Sep 2022 10:42:25 GMT
    expires
    	Thu, 29 Sep 2022 10:42:25 GMT
    server
    	LiteSpeed
    vary
    	Accept-Encoding,User-Agent
    	
    Accept
    	*/*
    Accept-Encoding
    	gzip, deflate, br
    Accept-Language
    	pl,en-US;q=0.7,en;q=0.3
    Alt-Used
    	www.***.pl
    Connection
    	keep-alive
    Cookie
    	cookie_policy_accept=yes; CONCRETE=***; CONCRETE_LOGIN=1; ccmAuthUserHash=***
    Host
    	www.***.pl
    Referer
    	https://www.***.pl/szkolenia
    Sec-Fetch-Dest
    	empty
    Sec-Fetch-Mode
    	cors
    Sec-Fetch-Site
    	same-origin
    TE
    	trailers
    User-Agent
    	Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0
    X-Requested-With
    	XMLHttpRequest

also

XML processing error: syntax error
Area: http://***/index.php/ccm/system/heartbeat?_=1664452822477
Line number: 1, column 1:
``

Found solution:
instead using View::element(‘file’) in header.php
use Loader::element(‘file’).
That way those elements will always load when view-mode and edit-mode.
I’m know Loader method is old.

BUT seems work on page without CACHE and on COPY with CACHE-on not.

Its funny to replay to my post, but I found WORKING solution.

So I used View::element() in theme header to load custom code, which was used in templates. Worked fine till comes 9.x. Code still worked for View but while I wanted change Design Template in Edit-mode I got error about function not found. So it seems View::element() not worked/loaded.

Workaround with minimal changes in code was in all block/templates or else where I use specific code, add IF(!function_exists) and then View::element(). And this solution worked in Edit but was not pretty.

So second solution I used from Documentation and Adding Custom Code.
I used namespaces and all custom code enclosed to classes (obj).
So I taken Legacy mode from Docs while without it does not worked for me (I found solution to this but not tested where folder: src should be renamed to Src). Must be enabled in application/config/app.php.
Created file exp. application/src/Custom/Example.php
In file namespace Application\Src\Custom and where I wanted use it use Application\Src\Custom\Example
Then $code = new Example() or Example::function().

So yeah, finly working.

Nice, thanks for including the solution here others to find! :+1: