News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

AJAX-related inquiry

Started by Biology Forums, August 09, 2018, 10:47:40 AM

Previous topic - Next topic

Biology Forums

Is it possible to dynamically load a function within a template file without loading the header and footer?

Assuming that the URL loads:

website.com/index.php?action=xyz

I've managed to work it by using exit(); at the very end, but in case there's a better method, I'd like to know.

Arantor

Set $context['template_layers'] to an empty array to skip them.

Biology Forums

On a similar note, how do I stop Google from crawling these AJAX-based pages?

Arantor

Don't link to them in the first place?

Failing that there is a directive you can set in $context to emit a no index, but I don't remember what it is offhand.

Biology Forums

Quote from: Arantor on August 10, 2018, 02:59:00 AM
Don't link to them in the first place?

Failing that there is a directive you can set in $context to emit a no index, but I don't remember what it is offhand.

It's hard not to, and even if I don't via some javascript code, search engines still get to them

Biology Forums

One more question based on my original inquery, I tried this:

function search()
{
global $context;

$context['template_layers'] = array();

echo'My Text';
}


It comes up as a white screen with "my text" then underneath: An Error Has Occurred! Unable to load the 'main' template.

What does that suggest?

Arantor

That suggests you haven't set up $context['sub_template'] to point to the template_ function that should be handling your output because separating out the logic of processing from its output is great.

If you need to spit out JSON and no other stuff, echo the json_encode then call obExit(false) to send without any other processing.


Advertisement: