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.
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.
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.
We’ve got a video on layouts up on EEU. Should get you up to speed quickly.
Layouts are a life saver!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.