ARTICLE

symfony1.4 の slot で Open Graph protocol(OGP)に対応する

以前、こんな投稿をしたのですが、修正するのを忘れていました。
こりゃーとんでもない対応の仕方です。

セオリー通りならば slot を使うのが普通です。 slot ってなんぞ?その1 / slot ってなんぞ?その2

テンプレートにはこのように書いておいて…

// apps/frontend/modules/unko/template.php

slot('ogp_properties', array(
    'fb:app_id'      => 'xxxxxxxxxxxxxxx',
    'og:title'       => 'unko title',
    'og:type'        => 'article',
    'og:image'       => public_path('uploads/unko.png', true),
    'og:url'         => 'http://unkopaku.paku/d/1',
    'og:description' => 'unko description',
    'og:site_name'   => 'unko name',
    'og:locale'      => 'ja_JP',
));

レイアウトには slot のキーが存在したら展開して出力する処理を書く。

// apps/frontend/templates/layout.php

if (has_slot('ogp_properties')) {
    foreach (get_slot('ogp_properties') as $k => $v) {
        echo '<meta property="', $l, '" content="', $v, '" />', "\r\n";
    }
}

これだけでいいんですよ。

blog comments powered by Disqus
  1. tetsuwo posted this

Categories