Q: Display fields within control when not null I have the following code:
  <% control StaffMembers %>
    <li>
        Name: <h2>$Name</h2>
    </li>
    <% end_control %>

I would like to ask how I would be possible to show the Name text field only if it is not null or empty.
An if statement within the control didn't work:
 <% control StaffMembers %>
   <% if $Name %>
     <li>
        Name: <h2>$Name</h2>
    </li>
   <% end_if %>
<% end_control %>

Thank you

A: Your code looks correct. Calling an if statement inside the control should work.
I would also recommend putting an if statement around your control to check if there are any StaffMembers before looping through them:
<% if $StaffMembers %>
    <ul>
    <% control $StaffMembers %>
        <% if $Name %>
        <li>
            Name: <h2>$Name</h2>
        </li>
        <% end_if %>
    <% end_control %>
    </ul>
<% end_if %>

Or in Silverstripe 3 using loop instead of control:
<% if $StaffMembers %>
    <ul>
    <% loop $StaffMembers %>
        <% if $Name %>
        <li>
            Name: <h2>$Name</h2>
        </li>
        <% end_if %>
    <% end_loop %>
    </ul>
<% end_if %>

