View Full Version : Can I Output A PHP Widget In a HTML Widget or Allign PHP Output
B16MCC
02-24-2012, 07:39 AM
Hi guys, I've got an existing PHP Direct Exec widget using the following code :-
ob_start();
include("radio_stats_martin.php");
echo "<br />\n";
$output .= ob_get_contents();
ob_end_clean();
This is working fine.
How would I display the output of that same radio_stats_martin.php in a Static HTML widget ?
Thanks
B16MCC.
I don't think you can. You can't run php as part of a static html widget. If the output never changes you could copy the output and paste it in an html widget. But if it's working the way it is, why would you want to change the widget type?
B16MCC
02-24-2012, 02:32 PM
OK Thanks. The reason was to do with formatting the output. I'll expand on what I'm trying to do and perhaps approach it from a different angle.
I have this code in a PHP widget.
ob_start();
include("radio_stats_martin.php");
echo "<br />\n";
$output .= ob_get_contents();
ob_end_clean();
ob_start();
include("radio_stats_alex.php");
echo "<br />\n";
$output .= ob_get_contents();
ob_end_clean();
As you can see, this is duplicate code but referring to 2 different php files.
The output is shown below.
https://vborg.vbsupport.ru/attachment.php?attachmentid=136660&stc=1&d=1330097329
The php files are checking the status of 2 different shoutcast servers and outputting to my widget based on wether the server is broadcasting or not, so this output is dynamic.
Basically I want to arrange the 2 outputs side by side rather than one below the other. The reason I asked about a HTML widget is because I could put the outputs into tables, or so I thought. As you've now confirmed I can't do that.
Any help is greatly appreciated.
Thanks for reading.
B
Oh, OK. You can do that in a php widget. You can just do something like:
ob_start();
include("radio_stats_martin.php");
$martin = ob_get_contents();
ob_end_clean();
ob_start();
include("radio_stats_alex.php");
$alex = ob_get_contents();
ob_end_clean();
$output = "<table><tr><td>$martin</td><td>$alex</td></tr></table>";
If you wanted you could use a template, maybe like this:
ob_start();
include("radio_stats_martin.php");
$stats['martin'] = ob_get_contents();
ob_end_clean();
ob_start();
include("radio_stats_alex.php");
$stats['alex'] = ob_get_contents();
ob_end_clean();
$templater = vB_Template::create('radio_stats');
$templater->register('stats', $stats);
$output = $templater->render();
Then create a radio_stats template with whatever html you want and put {vb:raw stats.martin} or {vb:raw stats.alex} wherever you want them.
BTW, I don't know why I used $martin and $alex in the first one but a $stats array in the second one - you could do it either way in either example).
B16MCC
02-24-2012, 02:55 PM
Thanks a lot. Those options are really useful.. I'll work something out from your example.
--------------- Added 1330099902 at 1330099902 ---------------
Sorry to be a pain, I've looked at the template method but I'm a little confused.
Could you give a little more detail on how I create this please ?
I'm confused about wether the code goes in a php file or in the template ?
--------------- Added 1330102316 at 1330102316 ---------------
Nah, struggling coming up with the template method. I'm just posting again in hope that the thread will be highlighted again. Thanks.
B16MCC
02-24-2012, 05:42 PM
Well eventually I got it looking how I want it. I've attached my code and a screen shot for anyone else it may help.
ob_start();
include("radio_stats_martin.php");
$martin = ob_get_contents();
ob_end_clean();
ob_start();
include("radio_stats_alex.php");
$alex = ob_get_contents();
ob_end_clean();
$output = "<center><table width='96%'><tr><td width='45%'><div class='cms_widget'>$martin</div></td><td width='10%'></td><td width='45%'><div class='cms_widget'>$alex</div></td></tr></table></center>";
https://vborg.vbsupport.ru/attachment.php?attachmentid=136667&stc=1&d=1330108898
Don't worry about the 'Current Song' text, that's actually a moving marquee. So that's why it looks a little odd on a screen grab.
Thanks so much for your help. I'm learning a lot here, Cheers.
Thanks for posting your result.
Yeah, unfortunately I usually miss it when the auto-merge kicks in so I missed your previous questions. But to answer, the template method should have worked by putting all the code I posted in a php widget and creating the template using the Style Manager.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.