Karl_T Posted May 2, 2018 Posted May 2, 2018 All solutions I found were using $useMain. It seems that Processwire is no longer supporting $useMain. How can I achieve the same as $useMain did? That is disabling the append and prepend _init.php and _main.php by API. I tried using die or exit(), but that would make TracyDebugger fail to work(not showing ajax information).
gebeer Posted May 2, 2018 Posted May 2, 2018 39 minutes ago, Karl_T said: It seems that Processwire is no longer supporting $useMain PW is still supoorting it if you are using the delayed output strategy in your templates. $useMain has become kind of a convention when using this strategy, but infact, it is just a user defined variable. You could call it $includeMain or whatever you want. How I use $useMain: 1. in my _init.php I define $useMain = true; So it is true by default and the _main.php will be appended to all template php files. In the top area of the _main.php I do somethinmg like this if(!$useMain) return; // if $useMain is set to false in a template php file, then do not render _main.php Then in the template where I don't want _main.php to get appended, I set $useMain = false; In your case, when you don't want to have _main.php appended for AJAX calls you can do this in the template that receives the AJAX request if($config->ajax) $useMain = false; Of course this concept only works for the delayed output strategy. 4
Karl_T Posted May 2, 2018 Author Posted May 2, 2018 Thanks @gebeer! It works with your method. I am using markup region by the way. I thought this variable was some kind of core API. 1
gebeer Posted May 2, 2018 Posted May 2, 2018 47 minutes ago, Karl_T said: I thought this variable was some kind of core API. @Karl_T Glad it works. Using markup regions implies the use of the delayed output strategy. So your good to go ? $useMain was introduced in the advanced site profile that ships with PW and has been around for quite a while. Since many people adapted that, you see $useMain mentioned a lot throughout the forum. But it has nothing to do with the API. 3
Autofahrn Posted May 2, 2018 Posted May 2, 2018 When I need to return something totally different from a template file, I'm doing something like this: if($config->ajax) { echo <Whatever>; $this->halt(); return; } Works ok for me. 1
Karl_T Posted May 2, 2018 Author Posted May 2, 2018 18 minutes ago, Autofahrn said: When I need to return something totally different from a template file, I'm doing something like this: if($config->ajax) { echo <Whatever>; $this->halt(); return; } Works ok for me. I remember that $this->halt() appears somewhere in the forum too. Just check. This works as well. Thank you! 1
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