Jump to content

use phpMyEdit in a Smarty template - encapsulate echo/print statements?


chiquero

Recommended Posts

Basically, I'm trying to get phpMyEdit to work with the Smarty template engine.

 

There doesn't seem to be an easy way to do this since the only way to display the results of phpMyEdit tables is to call the constructor:

 

new phpMyEdit($opts);

 

...phpMyEdit will then generate the table with a series of echo statements.

 

But it seems the only way to use the Smarty template is to feed the template file a bunch of variables.

 

...
$smarty->assign('var', 	$var);
$smarty->display('template.tpl.php');

 

So I would somehow have to get phpMyEdit to return a string of all its output.

 

Or maybe there is some way to encapsulate the echo statements into a buffer, bypass display and then store them in a string to send to the template engine.

 

I can't easily replace phpMyEdit since my client is committed to it, but I can use a different template engine if an alternate would solve this problem.

 

Thanks to anyone who can help!!

Solved.

 

I found this http://www.tequilafish.com/2009/02/10/php-how-to-capture-output-of-echo-into-a-local-variable/ which explains how to turn manipulate and store the output buffer using ob_start().

 

Here's the code:

 

// Store echo in string instead of displaying
ob_start();
new phpMyEdit($opts);
$pme_content = ob_get_contents();
ob_end_clean();

// Now pass string into the Smarty template
$smarty->assign('content', 	$pme_content);
$smarty->display('template.tpl.php');

 

 

I hope this helps someone out there who runs into this problem.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.