If empty title field?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
beattie
Forum Members
Forum Members
Posts: 98
Joined: Sun Dec 21, 2008 11:35 pm

If empty title field?

Post 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).
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: If empty title field?

Post 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 '***'
beattie
Forum Members
Forum Members
Posts: 98
Joined: Sun Dec 21, 2008 11:35 pm

Re: If empty title field?

Post 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?
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: If empty title field?

Post 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
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: If empty title field?

Post 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}
Post Reply

Return to “Modules/Add-Ons”