1

thumbnail私は自分が作成したページ (Facebook、Google、およびその他のサービスで使用するため) にとメタ タグの両方をog:image入力するのが好きで、私のアプローチを合理化しようとしています。

embed特定の画像アセットを持たないページを表示するときは、一般的なサイト全体の画像を指定し、必要に応じて特定の画像を指定できるようにしたい (変数を介して渡す)。

これが私のアプローチです:

{embed="_global/_header" thumbnail="http://mysite.com/images/articles/some-image.jpg"}

次に_header

{if embed:thumbnail}{preload_replace:thumbnail="{embed:thumbnail}"}{/if}
{preload_replace:thumbnail="{site_url}/assets/img/thumbnail.jpg"}

...

<meta name="og:image" content="{thumbnail}" />
<meta name="thumbnail" content="{thumbnail}" />

embedこれは、 (変数に設定された最初の値preload_replaceが使用され、後続の値が無視されるため)経由でサムネイル URL を渡す場合にうまく機能しますが、値を渡さない場合は、(割り当てられた値{thumbnail}を使用するのではなく) 空になります。 {site_url}/assets/img/thumbnail.jpg)。

ここで私のアプローチに誤りがある人はいますか? {thumbnail}その埋め込み変数を渡していないのに、条件内で解析される (空になる) のはなぜですか?

4

3 に答える 3

2

奇妙な EE 解析順序の問題を回避するために、次のように条件を記述してみてください。

{if "{embed:thumbnail}" == ""}
    {preload_replace:thumbnail="{embed:thumbnail}"}
{/if}

また、私はあまり詳しくありませんが、 Stashpreload_replaceを使用してこれを解決できますか? ページ テンプレートのさらに下からサムネイルを設定できるという追加の利点があります (たとえば、チャンネル コンテンツから動的に設定します)。

ページ テンプレートで:

{embed="_global/_header"}
{exp:stash:set name="thumbnail"}http://mysite.com/images/articles/some-image.jpg{/exp:stash:set}

ヘッダーに次を埋め込みます。

{!-- set the default thumbnail --}
{exp:stash:set name="thumbnail" replace="no"}http://mysite.com/images/default.jpg{/exp:stash:set}
<meta name="og:image" content='{exp:stash:get name="thumbnail"}' />
<meta name="thumbnail" content='{exp:stash:get name="thumbnail"}' />
于 2012-10-31T21:50:48.907 に答える
0

I've taken the same approach as Adrian is suggesting with meta data and it would work for your thumbnails too - thought it is generally a pretty different way of thinking about your templates. I described the approach in an earlier Stack Exchange answer to a question about populating the page tags with entry data without needing multiple entries loops here.

When I use stash for meta data, I will do effectively the same thing you want to do with your thumbnail - have conditional fallback to a default value when the entry-specific data is not entered/available. I run that conditional at the entry level and then stash:set the result. Then in the meta header - which is all part of my embedded layout wrapper template - I use stash:get to retrieve the stashed result. The same thing can be done with just about any data you want to set at one point in the parse order and get later in the parse order - regardless of where it appears in wrapper template since as an embed (and commonly the only one you would use in a stash setup) it's parsed later than your entries loop logic.

于 2012-11-01T11:17:31.210 に答える