I'm seeking a simple way to override {title} within the element of pages.
At present I have:
{title} | {sitename}
On some pages I wish to tweak titles whilst retaining the short page name in the admin pages list. I could, of course, assign a separate template using {description} in place of {title} and enter the title in the "Description (title attribute)" field in the page options. But, if possible, I'd rather use a single template.
Would it be possible to create a user defined tag that would get {description} only if it had content, else get {title}?
[solved] Override {title} in <title> element if {description} has content?
[solved] Override {title} in <title> element if {description} has content?
Last edited by Jonny on Mon Dec 06, 2010 7:30 pm, edited 1 time in total.
Re: Override {title} in <title> element if {description} has content?
Code: Select all
{if isset($description)}
<title>{$description} | {sitename}</title>
{else}
<title>{title} | {sitename}</title>
{/if}
Re: Override {title} in <title> element if {description} has content?
I was assuming that {description} was a smarty variable, not a smarty function, so it won't work... Search around, or look at the docs on the Smarty site to see how to capture the output of {description} to a variable, then do the above.
Re: Override {title} in <title> element if {description} has content?
{capture assign=somevariable}{description}{/capture}
{if isset($somevariable)}
{$somevariable} | {sitename}
{else}
{title} | {sitename}
{/if}
{if isset($somevariable)}
{$somevariable} | {sitename}
{else}
{title} | {sitename}
{/if}
Re: Override {title} in <title> element if {description} has content?
Thanks for both replies. I've tried your code, Ronny, both in my template and the Smarty data field within the page options.RonnyK wrote: {capture assign=somevariable}{description}{/capture}
{if isset($somevariable)}
{$somevariable} | {sitename}
{else}
{title} | {sitename}
{/if}
When a description has been entered it is displayed. When the description field is empty the {title} is not displayed - only the {sitename}.
With no description entered, I modified the {else} fallback, to say
sometext | {sitename}
"sometext" was not displayed, which led me to think that the empty {$somevariable} was still being parsed. I switched to this, which seems to work:
Code: Select all
{capture assign=somevariable}{description}{/capture}
{if $somevariable !=""}
<title>{$somevariable} | {sitename}</title>
{else}
<title>{title} | {sitename}</title>
{/if}
Re: Override {title} in <title> element if {description} has content?
It seems like the capture assigns an empty string if there is no {description}. It still is set, but empty, so "isset" isn't working as expected. If what you did works, then it should be good.
Re: Override {title} in <title> element if {description} has content?
OK, thanks, marked as [solved] then.