3

I have always displayed a channel entry's title like so:

{exp:channel:entries channel="news"}{embed="partials/.header" page_title="{title}"}{/exp:channel:entries}
  Body
{embed="partials/.footer"}

What is the best way of including the entry's title in the header partial template of the html?

// .header
<head>
 <title>{embed:page_title}</title>
</head>

2 Answers 2

5

I recommend using SEO Lite. It will save you from having to open up a channel:entries tag just to grab the title.

Plus it can be used for a meta description tag (which is also useful for og:description and social share text). And it has a variety of useful parameters to help you pull the right title and to add prefixes or suffixes to your title.

Just install the module and it creates a tab in the publish form.

OR...if you want something even simpler and only care about titles, then the Low Title plugin works great for that.

5
  • How would you use SEO Lite for Facebook open graph tags? The screenshots only show room for keyword/description textareas. Or does it give you access to other fields of the entry's channel?
    – notacouch
    Dec 3, 2013 at 16:32
  • @notacouch I'm sorry, my answer was misleading. It does only give you access to the SEO Lite-specific title, description, and keywords fields. So the only Facebook open graph tags you could cover via SEO Lite would be og:title and og:description. I updated my answer.
    – Alex Kendrick
    Dec 3, 2013 at 16:42
  • oh okay, thanks. Noticed there were updates to the add-on recently and that got me real curious. If what you said was true that would mean I wouldn't have to roll my own code! So I got real excited for a moment haha
    – notacouch
    Dec 3, 2013 at 17:01
  • 1
    For more advanced open graph options w/SEO Lite check out this gist: gist.github.com/bjornbjorn/4039233 Feb 18, 2014 at 12:05
  • @Bjørn that is awesome! I had no idea. Looking forward to trying that out.
    – Alex Kendrick
    Feb 19, 2014 at 16:36
2

The Variables plugin is a good option for passing data to the header embed.

The variables plugin gives the possibility to create variables (either static or dynamic) and use them later on. This means that for example you can set certain data and use it in the head (if it's embedded) without having to re-create a tag pair for the specific channel.

Set a variable like this inside your template:

{exp:variables:set name="entry_id" value="{entry_id}"}
OR
{exp:variables:set name="entry_id" value="1"}

And get it like this in the header:

{exp:variables:get name='entry_id'}
3
  • How does this work? Create variables where? How is this different from utilizing stash if variables are defined in templates or SEO Lite if defined in the control panel somewhere?
    – notacouch
    Dec 3, 2013 at 17:02
  • Just another way to do things... The variables are created in the main template and called in the header... Different from SEO Lite because you can create anything you want. I use it for open graph tags when needed and to pass EntryID to SEO Lite. I added code example for setting/getting in my answer.
    – Anna_MediaGirl
    Dec 3, 2013 at 18:50
  • 1
    Oh okay it's like a lighter version of Stash. Cool, thanks.
    – notacouch
    Dec 3, 2013 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.