path not displaying when display-name is blank
Hi,
I'm working on Cascade 7.8 and can't figure out why the attached
velocity script isn't displaying the page path when the
display-name's blank (like on lines 45, 71, 97 and 123 of the
attached index block)? Here's my if statement :
#if ( $display != "")
<li><a href="${link}">${_EscapeTool.xml($display)}</a></li>
#else
<li><a href="${link}">${path}</a></li>
#end
The script should list each page's display-name or path if display-name's blank. Thoughts?
Erik
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
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
1 Posted by Ryan Griffith on 22 Jan, 2015 06:50 PM
Hi Erik,
The issue is when there is no value for Display Name
$page.getChild("display-name")will returnnull. If you attempt to check either$page.getChild("display-name")or$page.getChild("display-name").value, Velocity will simply dump those statements as plaintext. This will cause your conditional to return true since technically speaking the variable is not an empty string.Instead, I suggest one of the following:
To be a little more self-documenting, you could use the Property Tool's
isNullmethod to check if the element is null:Please let me know if you have any questions.
Thanks!
2 Posted by espanae on 22 Jan, 2015 08:31 PM
Ryan, thanks for the quick reply. I tried your suggestion, which makes sense, but it still showed display-name instead of path. Here's an excerpt of the HTML now generated:
Attached is the code I tried. Let me know if you get something different.
3 Posted by Ryan Griffith on 22 Jan, 2015 09:10 PM
Thank you for testing and following up, Erik. My apologies the snippet I provided did not appear to work.
Oddly, using your sample XML as an XML Block and your original Format, I was able to get all but one page to output
false.I believe part of my issue with testing locally is, depending on your version of Cascade Server, I believe Index Blocks began omitting empty elements as opposed to using a self-closing tag. For example, i am seeing self-closing
<display-name/>elements in your sample XML whereas when I was testing locally with an existing Index Block I was not seeing any<display-name>elements.A little more complex, but you could possibly try the following:
Please let me know if you have any questions.
Thanks!
4 Posted by espanae on 23 Jan, 2015 02:49 PM
Thanks a bunch, Ryan.
The more complex code worked. I wouldn't have figured it out without your help.
-Erik
espanae closed this discussion on 23 Jan, 2015 02:50 PM.