Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Access attributes in Pages custom fields like label (name), etc


Recommended Posts

Hi there, I posted this at the IPS communities, but I thought it might get a little more direct attention over here.

In a Pages DB display template, I can get custom field data with


And In the Display are of the field, I can set the {$label} and the {$value} as well as use the {$formValue}

But what I really need to do is access the custom field's Name (label) and Description from within the Record Display template.

Is that possible?Something like:

{{foreach $record->customFieldsForDisplay('display_top') as $fieldId => $fieldValue}}
	custom field key: {$fieldId}

  // this doesn't exist, does it?
  // this doesn't exist



Link to comment
Share on other sites

  • Owner

You can get the label, that should not be a problem.

{$record->customFieldDisplayByKey($fieldId,'THIS VALUE')|raw}

The value after fieldID determine what template it will use. Listing is what you put in the listing settings, Display what you put in the display setting and raw output as if you set no settings, kindof 🙂

In the settings for display you can set custom and then in that area you can place just the label. Then you can use Display to post the label.

Description however I have never tried, but since it is part of the field object it should be possible to output somehow. It is intended for the form and in the admin area, so it might be a bit tricky to get for the presentation templates like display and listing.

Link to comment
Share on other sites

ooh! This is a great idea. Thanks for offering it. A nice workaround.

I'll set up {$label} for the 'listing' type and see what I can do. I wanted to do this in a somewhat automated way, though I could have inserted each field with a custom label in the template code:

Label: Programs
Data: {$record->customFieldDisplayByKey('programs','processed')|raw}

Label: Notes
Data: {$record->customFieldDisplayByKey('notes','processed')|raw}

But I like your idea much better as we have 30-40 fields.

Thank you!

Link to comment
Share on other sites

In case someone stumbles on this in the future, here is a way to get the Custom Field name in any database:
Remember to replace the <database_id> with the id for your Pages database, so for database ID 21, the code will look like this: \IPS\cms\Fields21::load ...

{{foreach $record->customFieldsForDisplay('display_top') as $fieldId => $fieldValue}}
  {{$field = \IPS\cms\Fields<database_id>::load( $fieldId, ‘field_key' );}}
  Custom field key: {$fieldId}
  Label: {$field->_title}
  Description: {$field->_description}
  Custom Field Value: {$record->customFieldDisplayByKey($fieldId,'processed')|raw}



Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Create New...