Harmster Posted September 9, 2013 Share Posted September 9, 2013 Hey, 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 More sharing options...
Philipp Posted September 9, 2013 Share Posted September 9, 2013 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. 1 Link to comment Share on other sites More sharing options...
Harmster Posted September 10, 2013 Author Share Posted September 10, 2013 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 More sharing options...
adrian Posted September 10, 2013 Share Posted September 10, 2013 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 More sharing options...
arjen Posted September 10, 2013 Share Posted September 10, 2013 Add $useMain = false; to your template and the html won't output. 4 Link to comment Share on other sites More sharing options...
ryan Posted September 14, 2013 Share Posted September 14, 2013 If you wanted it to automatically bypass the _main.php template during an ajax request, you could also do something like this in your _init.php: $useMain = !$config->ajax; 4 Link to comment Share on other sites More sharing options...
peterfoeng Posted January 17, 2014 Share Posted January 17, 2014 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 More sharing options...
peterfoeng Posted January 17, 2014 Share Posted January 17, 2014 I misunderstand this, all sorted! Cheers Link to comment Share on other sites More sharing options...
bytesource Posted August 15, 2014 Share Posted August 15, 2014 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? Cheers, Stefan Link to comment Share on other sites More sharing options...
bytesource Posted August 16, 2014 Share Posted August 16, 2014 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; 3 Link to comment Share on other sites More sharing options...
Jo J Posted August 13, 2019 Share Posted August 13, 2019 To whoever might be searching this topic, I just recently found out about $config->appendTemplateFile 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 = ''; $rss->render($items); exit; But for AJAX, i might be inclined to use the suggested solutions above. Link to comment Share on other sites More sharing options...
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