Thursday, 5 September 2013

Output Buffering php producing nothing - why isn't this working?

Output Buffering php producing nothing - why isn't this working?

In a Joomla template file (index.php) I am trying to get 2 parameters
which are set in the admin panel (then wrapped in some css formatting) to
create some basic css for google fonts and then save them to a separate
css file. Maybe my thoughts on this are all wrong, but here is what I am
TRYING to do but needless to say it is producing nothing...
<?php
ob_start();
?>
<?php echo $this->params->get('googleFont1types');?> {
font-family: '<?php echo str_replace('+', ' ',
$this->params->get('googleFont1'));?>', sans-serif;
}
<?php echo $this->params->get('googleFont2types');?> {
font-family: '<?php echo str_replace('+', ' ',
$this->params->get('googleFont2'));?>', serif;
}"
<?php
$googlefontcss = ob_get_contents();
ob_end_clean();
file_put_contents('googlefonts.css', $googlefontcss);
?>
Or do you know of a better way of doing this? I can easily write the
styles inline as css like the following (tested and working) - but I dont
want inline css ideally. I'd really like to just take this chunk of css
and write it to a text file.
<?php
// Use of Google Font
if ($this->params->get('googleFont'))
{
?>
<link href='http://fonts.googleapis.com/css?family=<?php echo
$this->params->get('googleFont1');?>|<?php echo
$this->params->get('googleFont2');?>' rel='stylesheet' type='text/css'
/>
<style type="text/css">
<?php echo $this->params->get('googleFont1types');?> {
font-family: '<?php echo str_replace('+', ' ',
$this->params->get('googleFont1'));?>', sans-serif;
}
<?php echo $this->params->get('googleFont2types');?> {
font-family: '<?php echo str_replace('+', ' ',
$this->params->get('googleFont2'));?>', serif;
}
</style>
<?php
}
?>

No comments:

Post a Comment