Is it possible to turn off layout only for ajax request?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
szimek

Is it possible to turn off layout only for ajax request?

Post by szimek »

Hi,

I got few pages that I'd like to make accessible for ajax and non-ajax clients. If user with js enabled clicks a link, I'd like to fetch a page (content *without* the layout) and display it in a div.  However, if user has js disabled, it should normally return the whole page (content *with* layout).

Is it possible to do wth CMS MS?

Regards
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Is it possible to turn off layout only for ajax request?

Post by calguy1000 »

try adding showtemplate=false to the url, or cntnt01showtemplate=false
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: Is it possible to turn off layout only for ajax request?

Post by piotrekkr »

for example :):
$this->CreateLink($id, 'action', $returnid, '', array('showtemplate' => 'false'), '', true);
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Is it possible to turn off layout only for ajax request?

Post by calguy1000 »

No, this solution should work in 1.2.x as well.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
piotrekkr
Forum Members
Forum Members
Posts: 38
Joined: Mon Mar 05, 2007 5:30 pm

Re: Is it possible to turn off layout only for ajax request?

Post by piotrekkr »

My solution work in 1.0.5 too :)
NaN

Re: Is it possible to turn off layout only for ajax request?

Post by NaN »

So far...
But what about Modules in the backend?
I try to create a simple mailer module that sends emails to users of the FrontendUsers module.
To prevent a server timeout I try to send the mails in multiple requests with ajax (similar to the NewsletterMadeSimple module).
My ajax request does not call an external php-file to send the mails. I'm using the moduleinterface.php with an action.sendMail.php instead. (e.g. the url that will be requested by the ajax script is moduleinterface.php?mact=MyModule,m1_,sendMail,0...) I believe this makes it more secure.
My problem is, that the response of the server contains the whole backend template.
But I just need an id...
The "showtemplate" param seems only to work for the frontend.
Is there any possibilty to realize an ajax request via backend without opening a new window? (like NMS)

(By the way: I don't want to use AJAX MadeSimple 'cause i've got my own very simple ajax request and i don't want my module to depend on more than the CMSMailerModule and FrontendUsers.)

Any ideas?
Last edited by NaN on Fri Jul 18, 2008 8:08 pm, edited 1 time in total.
NaN

Re: Is it possible to turn off layout only for ajax request?

Post by NaN »

Looking in the moduleinterface.php i found this:

Code: Select all


$USE_THEME = true;
if( isset( $_REQUEST[$id . 'disable_theme'] ))
{
	$USE_THEME = false;
}
else if( isset( $_REQUEST['disable_theme'] ))
{
	$USE_THEME = false;
}

So i just need to add the param disable_theme to my ajax request.
Quite simple.
But the response from the server still contains some comments, , and .
I have to modify the response via the javascript function replace().
So my request seems to work now.
But this cannot be a proper solution.
Is there any way to get just a single value as response from the moduleinterface.php?
Last edited by NaN on Sat Jul 19, 2008 11:16 am, edited 1 time in total.
NaN

Re: Is it possible to turn off layout only for ajax request?

Post by NaN »

When searching for that output i found some "issues" in the moduleinterface.php, header.php and footer.php.
It is hardcoded there:

moduleinterface.php line 139:

Code: Select all


if (!$suppressOutput)
{
	echo '</div>';
}

header.php line 10:

Code: Select all


if (isset($USE_THEME) && $USE_THEME == false)
  {
    echo '<!-- admin theme disabled -->';
  }

footer.php line 2 and 28-33:

Code: Select all


if (isset($USE_THEME) && $USE_THEME == false)
  {
    echo '<!-- admin theme disabled -->';
  }

...

?>

<__body>
</__html>

<?php

...



I just uncommented/modified it:

moduleinterface.php:

Code: Select all


# modified by NaN since we don't want ANY output from the admintheme if $USE_THEME == false
if (!$suppressOutput && isset($USE_THEME) && $USE_THEME!=false)
{
	echo '</div>';
}

header.php/footer.php:

Code: Select all


if (isset($USE_THEME) && $USE_THEME == false)
  {
	  # commented out by NaN since we don't want ANY output from the
	  # admintheme if $USE_THEME == false
	  # echo '<!-- admin theme disabled -->';
  }

...

if (isset($USE_THEME) && $USE_THEME != false)
{
	# modified by NaN since we don't want ANY output from the admintheme
	# if $USE_THEME == false
	echo "<__body>\n</html>";
}

Dunno if this is usefull but just in case...
oi_antz

Re: Is it possible to turn off layout only for ajax request?

Post by oi_antz »

Here's how I did it:

file: modules/FEUsers/ajax_cities_for_country.php

Code: Select all

<?php
while(ob_get_level()>0) ob_end_clean();

header('Content-type: text/javascript');
die(json_encode($cities));
Post Reply

Return to “Developers Discussion”