Jump to content

Disable append/prepend file in Ajax


Karl_T
 Share

Recommended Posts

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).

Link to comment
Share on other sites

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.

  • Like 4
Link to comment
Share on other sites

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.

  • Like 3
Link to comment
Share on other sites

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!

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...