We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Changing case of title that contains segment (Hi I'm Nick, I'm a newbie)

How Do I?

NicholasD's avatar
NicholasD
5 posts
6 years ago
NicholasD's avatar NicholasD

I’m using the Segment Variables as my page title like so:

<title> {if segment_1=="{homepage}”} {template_group} {if:elseif segment_3=="" && segment_2=="" && segment_1!=""} {segment_1} ….. </title>

My question is regards this part : {if:elseif segment_3=="" && segment_2=="" && segment_1!=""} {segment_1}

I am trying to capitalise {segment_1} to have my title as ‘Abc’ instead of ‘abc’ and have used :spellout like so {segment_1:spellout capitalize='ucwords'} but that spits out ‘Zero’ instead.

‘abc’ is my template group.

Any help with this natively in EE. Appreciate it.

       
James Mathias's avatar
James Mathias
225 posts
6 years ago
James Mathias's avatar James Mathias

Hi,

The most sustainable and best way to do browser titles in ExpressionEngine is with Layouts. https://docs.expressionengine.com/latest/templates/layouts.html#template-layouts

Specifically if you use a layout you can have a title like <title>{if layout:title} {layout:title} / {/if} {site_name}</title>

This allows you to send exactly the title you want formatted precisely as you need it to be.

In the template that is sending the title you’d use

{layout:set name='title'}
 {title}
{/layout:set}

Using Segments to construct a title takes a lot of conditions, and you end up with titles that have hyphens or underscores in them.

Also, I don’t believe that the variable modifiers like spellout work on the segment variables.

       
NicholasD's avatar
NicholasD
5 posts
6 years ago
NicholasD's avatar NicholasD

Thank you James will get layout a shot. I had actually used :replace {last_segment:replace find='-' replace=' '} to solve the hyphen problem, but I’m sure I would have come across an impasse sooner or later with that solution.

Anyhoo will give layout a shot (headscratch). Thanks.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
6 years ago
Robin Sowell's avatar Robin Sowell

We’ve got a video on layouts up on EEU. Should get you up to speed quickly.

Layouts are a life saver!

       
NicholasD's avatar
NicholasD
5 posts
6 years ago
NicholasD's avatar NicholasD

Thanks Robin, the video helped. Layouts are definitely the way forward.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.