dongqiang8058 2014-06-27 11:29 采纳率: 100%
浏览 22
已采纳

在Zend Framework 2中向<head>标记添加自定义HTML

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?

  • 写回答

1条回答 默认 最新

  • dpa84373 2014-06-27 11:39
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示