I'm trying to add some custom html tags to my head script in my layout via. the controller. My ultimate goal is to add the following inside my head tags:
<noscript><meta http-equiv="refresh" content="5"></noscript>
I'm able to add the refresh meta tag itself using $headMeta->appendHttpEquiv()
, but I have no idea how I can wrap that in the <noscript></noscript>
tags. This only needs to be added to one page, but I don't want a separate layout file for this. I also want to use whatever methods and functions ZF2 have on offer (if any fit the bill). I've gone through the documented view helpers, but I can't find one that will help.
Any ideas?
You should be able to do this with the placeholder helper.
In your layout:
<html>
<head>
<?=$this->placeholder('customHead')?>
[etc.]
Then in the view for the the page you want it on:
$this->placeholder('customHead')->set('<noscript><meta http-equiv="refresh" content="5"></noscript>');
change customHead
to whatever name you want.
Edit: Yes, you can do this in a controller action instead:
public function someAction()
{
$viewHelperManager = $this->getServiceLocator()->get('viewhelpermanager');
$placeholder = $viewHelperManager->get('placeholder');
$placeholder->getContainer('customHead')->set('<noscript><meta http-equiv="refresh" content="5"></noscript>');
}
if it's something you need to do in more than one place you might wish to inject the placeholder helper into the controller as a dependency.