Jump to content

"Reset" $config->appendTemplateFile for certain templates


Recommended Posts


I am using the Foundation 4 Site Template that Ryan made and I am currently working on a template that is going to be called via ajax and I'd like to just generate the content of the template itself instead of the all the appended/prepended content that the config adds.

How do I "reset" the config properties for just 1 template to the default setting?

Thanks in advance.

Link to comment
Share on other sites

I'm note sure if it is possible to "reset" the config for a single template.

You can check, if the page is requested via AJAX. In your prepended php, add a if-statement like:

if($config->ajax == false ) {
// Your init.php or code ...
//Nothing happens if it is an ajax request.

The file will still be appended but this time no code or markup will be added. The $config->ajax is a PW function which is set to true, if it is an AJAX JS Request.

  • Like 1
Link to comment
Share on other sites

The thing is that even with this code the template file will still be apended and you'll get the complete html page with <head> <body> etc and I don't need that, I want just 1 html string or a json string without the template files. Sorry if I wasn't clear.

Link to comment
Share on other sites

Does the "template" that you are calling via ajax really need to be a template file with a PW page that it is attached to?

If you place it in the website root folder and call it from there, PW will leave it alone.

I have done that with files that process ajax form submissions and it should work for your purposes as well.

Link to comment
Share on other sites

  • 4 months later...

Hi guys,

I wondering if $useMain is still working. I have my setup like this in the config.php

$config->prependTemplateFile = 'Init.php';

 * appendTemplateFile: PHP file in /site/templates/ that will be loaded after each page's template file
 * Uncomment and edit to enable.
$config->appendTemplateFile = 'Default.php';

Then I set the $useMain = false; as suggested but the default is still being output, maybe I am doing something wrong in the Init.php

Thanks guys

Link to comment
Share on other sites

  • 6 months later...

Just like described above I have a page with a template that is called via ajax. In order to disable $config->appendTemplateFile (named _done.php in my case), I put the following line in _init.php:

$useMain = !$config->ajax; 

However, _done.php still gets called. Is $useMain some kind of special variable? 



Link to comment
Share on other sites

I found the answer myself. In the Foundation Site Profile, $useMain is initially set to true in _init.php and checked in _main.php:

/templates/_init.php (line 40)

/* * Whether to include the _main.php markup file? 
For example, your template * file would set it to false when generating a page 
for sitemap.xml * or ajax output, in order to prevent display of the main <html> 
document. * */

$useMain = true;

/templates/_main.php (line 14)

// if any templates set $useMain to false, abort displaying this file 
// an example of when you'd want to do this would be XML sitemap or AJAX page. 

if(!$useMain) return;
  • Like 3
Link to comment
Share on other sites

  • 4 years later...

To whoever might be searching this topic, I just recently found out about 


and started using it in a delayed template method.

In my xml type templates (e.g. rss.php), "exit" seems to have the same effect (bypassing the _main.php template).

if(input()->urlSegment1 != 'rss') throw new Wire404Exception();
$rss = wire('modules')->get('MarkupRSS');
$rss->title = 'RSS Feed';
$rss->description = '';


But for AJAX, i might be inclined to use the suggested solutions above.

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

  • Recently Browsing   0 members

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