Jump to content

Recommended Posts

Posted

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!

Posted
if ($page->$field) {
	// do stuff
} else {
 // skip 
}

should do the trick. if you have some Pagearray fields then check if field is array and it has count() > 0 then do stuff

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
×
×
  • Create New...