Jump to content

skip only empty fields in for loop


Lmwt
 Share

Recommended Posts

Hi forum,

I have this list of fields with labels and I want to skip the displaying of labels for fields left empty (e.g. if field "logo" is not filled with an image, but it could also be text fields). Using count() and "continue" will always output either nothing or all labels.

Is there a way to use the "skipLabel" method in the loop?


foreach ($page->template->fields as $field) {

  if(!count($page->$field->logo)) {continue;}
  
  else {
  $etikette = $field->getLabel(); //get label in the current user language
  $content .= " <br><li class='pub-field'>$etikette<br> </li>"; //display labels as li
  $content .= $page->get($field->name) . "<br>"; // display values as li
  }  
}

Thanks for your help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...