user2610146
user2610146

Reputation: 179

CakePhp3 Meta description

I wanted to ask, if there is a way to assign meta description tag from view file ? I know, that this code inside my .ctp file will work fine:

// Assign title tag
$this->assign('title','Page title);

I have tried :

$this->Html->assing('description','description']);

But without success.

Or, if this is not possible, how set meta description, but not from layout? This works, but only in layout view file:

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

Upvotes: 0

Views: 819

Answers (1)

Use the block option for the meta() function (http://api.cakephp.org/3.0/class-Cake.View.Helper.HtmlHelper.html#_meta)

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

And then echo the meta block in your layout:

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

Upvotes: 3

Related Questions