Jim Bailie Posted October 9, 2023 Posted October 9, 2023 Hello - My _init.php file is running twice and it's become urgent. The screenshot below is on the home page of a simple echo 'In Init'. There is nothing fancy going on on the home page that could lead to any path of inquiry. (See thread below AND the github issue referenced therein) Therefore, this is leading me to thing that it has something to do with regions perhaps. // _main.php <div id="main-content"> <footer>Footer content</footer> </div> // template: home.php <div pw-prepend="main-content" class="min-h-full flex flex-col justify-center items-center bg-gray-200"> Some content </div>
elabx Posted October 9, 2023 Posted October 9, 2023 Do you have the regions configuration set to true?? In site/config.php $config->useMarkupRegions = true; 1
Jim Bailie Posted October 9, 2023 Author Posted October 9, 2023 @elabx Thanks, yes. On other pages, I believe this is now interfering with a SAML check/authentication process as well. $config->prependTemplateFile = '_init.php'; /** * Append template file * * PHP file in /site/templates/ that will be loaded after each page's template file. * Example: _main.php * * @var string * */ $config->useMarkupRegions = true; $config->appendTemplateFile = '_main.php';
da² Posted October 9, 2023 Posted October 9, 2023 9 hours ago, Jim Bailie said: The screenshot below is on the home page of a simple echo 'In Init'. You are referring to an echo in a template code that you see twice? That's expected. The code is not ran twice, I don't remember exactly how it works but your echo is like catched by render buffer, in addition to be displayed one time immediately. 1
ryan Posted October 9, 2023 Posted October 9, 2023 @Jim Bailie Your _init.php is called for every $page->render(); so if you've got more than one page rendering in the request, _init.php will be called for both of them. One example of that would be if your template file does a wire404(); then _init.php would be called for the page that started rendering, and also for the 404 page. The reason for this is that _init.php usually establishes variables and such that you might want to populate or use in your template file or in your _main.php, so it has to be called on every page render. If you have a need for it to only be called once, such as if you are defining functions in it, then just move the contents of your _init.php to another file, like _init-once.php (or whatever you want to name it), and then do this from your _init.php: include_once('./_init-once.php'); 3 1
Jim Bailie Posted October 9, 2023 Author Posted October 9, 2023 Thanks all. @ryan I will do this immediately, thanks!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now