Help with checking for title or display name

kmcdowell's Avatar

kmcdowell

11 Aug, 2014 10:35 PM

I pulled the format for Sitemap-HTML directly from the Hannon Hill GitHub, 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").

I'm very new to velocity, so maybe it's something very obvious that I'm missing. Any help would be appreciated. Thanks!

  1. 1 Posted by Ryan Griffith on 12 Aug, 2014 11:57 AM

    Ryan Griffith's Avatar

    Hi,

    Sometimes Velocity can be a little picky when it comes to variables. Curious, perhaps try setting $thePageTitle to an empty string at the very top of the macro to see if that "resets" the variable each time the macro is called:

    #set ( $thePageTitle = "" )
    

    Please let me know how the adjustment works out, or if you have any questions.

    Thanks!

  2. 2 Posted by kmcdowell on 12 Aug, 2014 05:07 PM

    kmcdowell's Avatar

    I tried setting $thePageTitle 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.

    Thanks!

  3. 3 Posted by Ryan Griffith on 12 Aug, 2014 06:09 PM

    Ryan Griffith's Avatar

    Thank you for trying the suggested change, my apologies it did not work out.

    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 Preview Options when editing the Format.

    Please let me know if you have any questions.

    Thanks!

  4. 4 Posted by Ryan Griffith on 20 Aug, 2014 02:33 PM

    Ryan Griffith's Avatar

    Hi,

    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 my most recent comment?

    Please feel free to let us know if you have any other questions.

    Thanks!

  5. 5 Posted by kmcdowell on 25 Aug, 2014 04:36 PM

    kmcdowell's Avatar

    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!

  6. 6 Posted by Ryan Griffith on 29 Aug, 2014 01:20 PM

    Ryan Griffith's Avatar

    Hi,

    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 #if statement check to see if the variable is not null and not empty.

    When you have a moment, try something like the following and let me know how it works out:

      #set ( $thePageTitle = "" )
      #set ( $thePageTitle = $formItem.getChild("title") )
      #if ( $thePageTitle && $thePageTitle.value != "" )
        ...
      #else
        ...
      #end
    

    Please let me know if you have any questions.

    Thanks!

  7. Ryan Griffith closed this discussion on 12 Sep, 2014 12:57 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac