Page 1 of 1
If empty title field?
Posted: Mon Feb 04, 2013 8:09 am
by beattie
I am trying trying to get a page title to show up only if the 'title' field is not empty. Here is my code but it's not working, I don't know why, any ideas welcome!
Code: Select all
{capture assign="titlehdg"}{title}{/capture}
{if !empty($titlehdg)}
<h1>{title}</h1>
{else}
{/if}
Is it perhaps that 'title' is a required field? (there is an asterisk besides the title field in edit content, yet it allows me to save the page without content in the field).
Re: If empty title field?
Posted: Mon Feb 04, 2013 10:12 am
by psy
You're right about the title field being required. Try putting in a string in the title field that you can match against eg "***". Then use your {if} statement to test for '***'
Re: If empty title field?
Posted: Mon Feb 04, 2013 10:26 am
by beattie
Thanks for your reply. If I put a string in the title field, then it isn't empty, so it shows up. If I leave it empty, it shows up as the menu text. Either, way, empty or not, the code doesn't work. There must be some code in the core which says "if title field is empty then replace with menu text" perhaps?
Re: If empty title field?
Posted: Mon Feb 04, 2013 10:52 am
by psy
OK, then do a 2nd test for the menutext, eg
Code: Select all
{if $mytitle eq "***" and $mymenutext eq "***"}
...
{/if}
or
Code: Select all
{if $page_alias eq "..."}
....
{/if}
Maybe you just have to work through the possibilities until you get the right result.
hth
psy
Re: If empty title field?
Posted: Mon Feb 04, 2013 6:36 pm
by Dr.CSS
This isn't exactly correct..?
{capture assign="titlehdg"}{title}{/capture}
{if !empty($titlehdg)}
<h1>{title}</h1>
{else}
{/if}
Maybe..?
{title assign="titlehdg"}
{if !empty($titlehdg)}
<h1>{$titlehdg}</h1>
{else}
{/if}