【问题标题】:Using Meta Description in the right place CakePHP 3在正确的地方使用元描述 CakePHP 3
【发布时间】:2016-04-20 17:28:51
【问题描述】:

我正在尝试在 cakephp 3 中使用元标记和描述。到目前为止它正在工作,但我面临的问题是我无法将它放在我的页面中,因为我的 .ctp 文件呈现在我的默认.ctp

例如,我的 default.ctp 中有我的菜单、页脚等,而我的 faq 页面在 faq.ctp 我如何推送这些

<?php
echo $this->Html->meta('description','enter any meta description here');
?>

head 标签中的元描述?我需要像 smarty 这样的模板语言并使用块吗?

【问题讨论】:

    标签: cakephp metadata smarty head cakephp-3.x


    【解决方案1】:

    在布局中:

    <?php
    echo $this->Html->meta('description',$description);
    ?
    

    在您的 faq.ctp 或 faq() 方法中:

    <?php
    $this->set('description','enter any meta description here');
    ?
    

    【讨论】:

    • 哇,好简单!非常感谢@Salines!
    【解决方案2】:

    将此添加到您的 ctp 文件中(没有回声

    <?php $this->Html->meta('description', 'some text here', ['block' => true]);?>
    

    这一行进入你的布局

    <?php echo $this->fetch('meta');?>
    

    另请参阅标题类似的问题:$this->set('title', 'Title Name'); not working in CakePHP 3.x

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      相关资源
      最近更新 更多