Page 1 of 1

[SOLVED] How to avoid template echo

Posted: Fri Feb 15, 2013 1:02 pm
by nervino
Hello, is there a way to avoid cmsms template display when echoing a variable from inside a module?
I'm generating an html page on the fly, storing its html code in a variable ($html_body), and forcing a file download, in this way:

Code: Select all

$filename = 'myfilename__'.strtolower(str_replace(" ", "_", $username)).'__'.time().'.html';

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; charset=utf-8 "); 
header("Content-Transfer-Encoding: binary");

echo ($html_body);
The downloaded file also contains the cmsms template, while I should need it has only the html I put in $html_body var.

How can I disable cmsms template? Is there a way to use something like "showtemplate=false"?
(I hope my explanation was quite clear...)

thank you

Re: How to avoid template echo

Posted: Fri Feb 15, 2013 4:52 pm
by calguy1000
for frontend actions you can use showtemplate=false
also actions that send files, and/or do ajax should exit() at the end rather than return back to CMSMS control.

Re: How to avoid template echo

Posted: Fri Feb 15, 2013 5:06 pm
by nervino
Thank you, Calguy. I already put an exit() immediately after the "echo($html_body)", but the template header is still present (but with no stylesheets) in the generated file.
For showtemplate=false: I didn't understand how to use it because I'm not using a link; I have a form (in action.default.php) whose action calls the page that creates the html file (action.do_html.php).
I have tried to put an hidden field in the form with "array('showtemplate', false)" but it doesn't work.

Is there a way to pass the showtemplate parameter using a form instead of an url?

Re: How to avoid template echo

Posted: Fri Feb 15, 2013 5:45 pm
by calguy1000
You will also have to clear all output buffers before you output your headers. This should do it.

Code: Select all

$handlers = ob_list_handlers(); 
for ($cnt = 0; $cnt < sizeof($handlers); $cnt++) { ob_end_clean(); }

Re: How to avoid template echo

Posted: Fri Feb 15, 2013 6:48 pm
by nervino
Thank you, Master. It works.