[SOLVED] How to avoid template echo

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
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

[SOLVED] How to avoid template echo

Post 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
Last edited by nervino on Fri Feb 15, 2013 6:48 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to avoid template echo

Post 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.
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.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: How to avoid template echo

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to avoid template echo

Post 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(); }
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.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: How to avoid template echo

Post by nervino »

Thank you, Master. It works.
Post Reply

Return to “Developers Discussion”