Showing Template

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
ross2376
New Member
New Member
Posts: 5
Joined: Fri Feb 01, 2008 9:31 pm

Showing Template

Post by ross2376 »

I have an action in my module (action.ExportExcel.php) to export a list of contacts from DB to excel...as the name implies. The problem is this: The excel sheet gets exported (downloaded) with the entire template of the template. How do I make CMSMS not display the template for this specific admin action?
Duketown

Re: Showing Template

Post by Duketown »

ross2376,

Not quite clear to me what you mean with
entire template of the template
. I take it that you do something like:
Retrieve a row from the database;
Format its fields by catenating them with delimiters;
Write the formated row to a .csv file (not sure if this would be on the server or for example on your c:\ drive);
Close the .csv file;
Open .csv using Excel.

Please provide us with the steps taken.
Maybe action.exportquiz.php from the module Quizzard can be of help.
ross2376
New Member
New Member
Posts: 5
Joined: Fri Feb 01, 2008 9:31 pm

Re: Showing Template

Post by ross2376 »

Code: Select all

	if (!isset($gCms))
		exit;

	# Assign smarty variable by reference for easier use and cleaner code
	$Smarty =& $this->smarty;

	# Check appropriate user permissions
	if (!$this->CheckPermission($this->Lang('PermissionExport')))
		header('Location: http://' . $_SERVER['SERVER_NAME'] . '/admin');

	# Generate administrative navigation
	$this->DisplayAdminNav($id, $params, $returnid);
	
	# Clean output buffers
	@ob_clean();
	@ob_clean();
	
	# Send headers to identify as excel document
	header('Content-type: application/vnd.ms-excel; name=\'excel\'');
	header('Content-Disposition: attachment; filename=Contacts.xls');
	header('Pragma: no-cache');
	header('Expires: 0');

	# Retrieve array of contact objects
		$Contacts = $this->GetContact();

		# Perform misc operations to ready data for listing
		foreach ($Contacts AS $key => $value)
			$Contacts[$key]->Date = date('F j, Y g:i A', $Contacts[$key]->Date);

		$Smarty->Assign('Contacts', $Contacts);

	# Display Template
	echo $this->ProcessTemplate('ExportExcel.tpl');
	
	# Exit application
	exit;
I just want it to export these contacts to Excel...which it will do. The only problem is the excel sheet shows the entire CMS admin template (menus..footers...etc) with it instead of just my ExportExcel.tpl template. I thought about just making a standalone script that doesnt use a CMS module action but thats tacky in my mind. How do I make this action not load the global template?
alby

Re: Showing Template

Post by alby »

ross2376 wrote: I thought about just making a standalone script that doesnt use a CMS module action but thats tacky in my mind. How do I make this action not load the global template?
View Printing module and PDF creation (createpdf.php)

Alby
ross2376
New Member
New Member
Posts: 5
Joined: Fri Feb 01, 2008 9:31 pm

Re: Showing Template

Post by ross2376 »

Thanks. I looked that up and I found the ContentPostRender() method to control content posting, however, this seems to only be valid for the frontend? My action is an admin action. How can I control admin content?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Showing Template

Post by calguy1000 »

the link to your action should have 'showtemplate=false' as one of the parameters.

See how the Uploads module, and other similar modules (modules that send files).
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.
ross2376
New Member
New Member
Posts: 5
Joined: Fri Feb 01, 2008 9:31 pm

Re: Showing Template

Post by ross2376 »

Code: Select all

$ExportLink = $this->CreateLink($id, 'ExportExcel', $returnid, 'here', array('showtemplate' => 'false'));
Is that correct?

If so, that didn't work for me.
ross2376
New Member
New Member
Posts: 5
Joined: Fri Feb 01, 2008 9:31 pm

Re: Showing Template

Post by ross2376 »

Anyone??
Post Reply

Return to “Developers Discussion”