check if a block chooser is empty

lauren.fraser's Avatar


09 Jan, 2014 03:15 AM

I'm modifying the format for our calendar to use a block chooser for the contact information. What is the best way to check if a block chooser is empty? I tried this in my script, but it displays $_SerialializerTool.serialize($contactInfo, true) if the block is empty. Is there a way to check if a node exists, instead of checking if a node is empty? I'm using the SerializerTool because in some of our contact blocks there is html (just not the sample I provided below).

#if ($contactInfo.value != "") <dt>Contact:</dt> <dd> $_SerializerTool.serialize($contactInfo, true) </dd> #end

block xml:
<contact type="block"> <content>(417) 328-6302</content> <path>/_internal/blocks/contact-info/birth-place</path> <site></site> <name>birth-place</name> </contact>

Empty block xml:
<contact> <path>/</path> </contact>

  1. 1 Posted by Ryan Griffith on 09 Jan, 2014 01:57 PM

    Ryan Griffith's Avatar

    Hi Lauren,

    The best way to accomplish this is to check to see if the value of the chooser's path is equal to /. For all choosers, when there is no asset selected you will have a path of /; otherwise, there will be a value like the example you provided.

    Also, when outputting the contents of the chooser, specifically the block chooser, you will want to use the SerializerTool on the <content> element and not the entire chooser element.

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

    #if ($contactInfo.getChild("path").value != "/") 
      <dd> $_SerializerTool.serialize($contactInfo.getChild("content"), true) </dd> 

    Note: I am assuming you are assigning the chooser element to the $contactInfo variable.

    Please let me know if you have any questions.


  2. 2 Posted by lauren.fraser on 09 Jan, 2014 03:20 PM

    lauren.fraser's Avatar

    Worked great. I checked $contact path, since I had set the $contactInfo variable to get the <content>element.

    Thanks again!

  3. 3 Posted by Ryan Griffith on 09 Jan, 2014 03:28 PM

    Ryan Griffith's Avatar

    Thank you for following up, Lauren. I am glad to hear that did the trick.

    Have a great day!

  4. Ryan Griffith closed this discussion on 09 Jan, 2014 03:28 PM.

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

Keyboard shortcuts


? 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