Reputation: 704
I have a PHP function that outputs quote marks like so when rendered in the html.
onload="this.rel='stylesheet'"
What I want is the following:
onload="this.rel='stylesheet'"
Here is the function causing the first example to happen - does anyone know how I can solve this?
public function get_css($opts, $index, $count)
{
$out = array();
$version = filemtime($_SERVER['DOCUMENT_ROOT'].'/assets/css/app.min.css');
$str = "this.rel='stylesheet'";
$out[] = $this->_single_tag('link', array(
'rel'=>'preload',
'as'=>'style',
'type'=>'text/css',
'href'=>'/assets/css/app.min.'.$version.'.css',
'onload'=>$str,
));
return implode("\n\t", $out)."\n";
}
Here is the function for _single_tag
protected function _single_tag($tag=false, array $attrs)
{
if ($tag===false) return;
return PerchXMLTag::create($tag, 'single', $attrs);
}
Upvotes: 0
Views: 72
Reputation: 983
The problem comes from the PerchXMLTag::create()
method which does some HTML encoding on the values supplied to it.
Looking at the Perch documentation there doesn't seem to be a way to disable this, so my suggestion would be to replace the code within the get_css
function with something that just outputs the raw HTML:
public function get_css($opts, $index, $count)
{
$out = array();
$version = filemtime($_SERVER['DOCUMENT_ROOT'].'/assets/css/app.min.css');
$str = "this.rel='stylesheet'";
$out[] = "<link rel='preload' as='style' type='text/css' href='/assets/css/app.min.{$version}.css' onload='{$str}' />";
return implode("\n\t", $out)."\n";
}
Upvotes: 1
Reputation: 1828
public function get_css($opts, $index, $count)
{
$out = array();
$version = filemtime($_SERVER['DOCUMENT_ROOT'].'/assets/css/app.min.css');
$str = "this.rel=\"stylesheet\"";
$out[] = $this->_single_tag('link', array(
'rel'=>'preload',
'as'=>'style',
'type'=>'text/css',
'href'=>'/assets/css/app.min.'.$version.'.css',
'onload'=>$str,
));
return implode("\n\t", $out)."\n";
}
Try with that.
Upvotes: 0