tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/10451-help-with-checking-for-title-or-display-nameCascade CMS: Discussion 2014-09-12T12:57:47Ztag:help-archives.hannonhill.com,2010-02-09:Comment/341035082014-08-11T22:35:55Z2014-08-11T22:35:56ZHelp with checking for title or display name<div><p>I pulled the format for Sitemap-HTML directly from the <a href=
"https://github.com/hannonhill/Velocity-Cookbook/blob/master/Sitemap-HTML/sitemap.vm">
Hannon Hill GitHub</a>, but the part that is meant to check for a
title, display name, or system name isn't quite working for me.
When I don't have a title, but do have a display name for a page,
it's ignoring the display name and taking the title from the
previous page instead. See the highlighted part of my attached
screenshot. Instead of using the display name that I entered in the
metadata field for this page ("Display - 2.3"), it's using the
title from the page above it ("Title - 2.2").</p>
<p>I'm very new to velocity, so maybe it's something very obvious
that I'm missing. Any help would be appreciated. Thanks!</p></div>kmcdowelltag:help-archives.hannonhill.com,2010-02-09:Comment/341035082014-08-12T11:57:14Z2014-08-12T11:57:14ZHelp with checking for title or display name<div><p>Hi,</p>
<p>Sometimes Velocity can be a little picky when it comes to
variables. Curious, perhaps try setting <code>$thePageTitle</code>
to an empty string at the very top of the macro to see if that
"resets" the variable each time the macro is called:</p>
<pre>
<code>#set ( $thePageTitle = "" )</code>
</pre>
<p>Please let me know how the adjustment works out, or if you have
any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/341035082014-08-12T17:07:15Z2014-08-12T17:07:15ZHelp with checking for title or display name<div><p>I tried setting <code>$thePageTitle</code> to an empty string at
the top of the macro, as you suggested, but there was no change to
the output. I would be open to trying something else if you have
any other suggestions. Otherwise, I might just go back to the XSLT
version, which seems to be working.</p>
<p>Thanks!</p></div>kmcdowelltag:help-archives.hannonhill.com,2010-02-09:Comment/341035082014-08-12T18:09:52Z2014-08-12T18:09:52ZHelp with checking for title or display name<div><p>Thank you for trying the suggested change, my apologies it did
not work out.</p>
<p>When you have a moment, please attach an XML sample being
applied to the Format and I would be happy to take a closer look in
my local environment. An XML sample can be obtained using the
<em>Preview Options</em> when editing the Format.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/341035082014-08-20T14:33:40Z2014-08-20T14:33:40ZHelp with checking for title or display name<div><p>Hi,</p>
<p>I was going over some older discussions and noticed this one is
still open. Were you able to get your Format working? If not, did
you have a chance to read over <a href=
"http://help.hannonhill.com/discussions/velocity-formats/10451-help-with-checking-for-title-or-display-name#comment_34115035">
my most recent comment</a>?</p>
<p>Please feel free to let us know if you have any other
questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/341035082014-08-25T16:36:02Z2014-08-25T16:36:02ZHelp with checking for title or display name<div><p>I wasn’t able to get it to work, but ended up using XSLT
instead. I am trying to learn velocity though, so I may come back
to it later, when I have more time. Thanks!</p></div>kmcdowelltag:help-archives.hannonhill.com,2010-02-09:Comment/341035082014-08-29T13:20:55Z2014-08-29T13:20:55ZHelp with checking for title or display name<div><p>Hi,</p>
<p>My apologies for not responding sooner. I am sorry to hear my
proposed solution did not pan out. Another solution I have seen is
to set the variable to an empty string, then attempt to set it to
the value of the element, and in the <code>#if</code> statement
check to see if the variable is not null and not empty.</p>
<p>When you have a moment, try something like the following and let
me know how it works out:</p>
<pre>
<code> #set ( $thePageTitle = "" )
#set ( $thePageTitle = $formItem.getChild("title") )
#if ( $thePageTitle && $thePageTitle.value != "" )
...
#else
...
#end</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffith