check for empty textValue using getStructuredDataNode
We have a staff foreach where we output 6 required fields and 1 optional. All our required fields come in fine but as soon as 1 optional field is populated, the format populates all the other optional fields with that one value... I obviously only want the field to show if it has a value but it seems the system thinks it always has a value.
#set ($creds = $asset.getStructuredDataNode("credentials").textValue)
#if($creds.value !=""), $creds#end
^^ this code shows all the all the same values as the only value set
#if($asset.getStructuredDataNode("credentials").textValue !=""), $asset.getStructuredDataNode("credentials").textValue#end
^^ this code shows the value of the one populated field and then " , $asset.getStructuredDataNode("credentials").textValue " for the rest...
How do I check if the credentials field is populated?
Thanks in advance!
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 Nando on 28 Apr, 2016 03:19 PM
Just tried:
this code shows the value of the one populated field and then " , $creds.textValue " for the rest...
2 Posted by Nando on 28 Apr, 2016 03:27 PM
ok then... this seems to work:
3 Posted by Ryan Griffith on 28 Apr, 2016 05:31 PM
Hi Nando,
You got it, I am glad to see you were able to find the solution.
When the node has no value the
textValue
property will returnnull
. This is why you were seeing the literal code being output instead of the value (or nothing), because Velocity will simply "dump" the code if you try to output null (since it's technically a Null Pointer Error).I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.
Have a great day!
Ryan Griffith closed this discussion on 28 Apr, 2016 05:31 PM.