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
 

                    {$record->customFieldDisplayByKey('programs')|raw}

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?
  {$record->customFieldDisplayByKey($fieldId,'LABEL')|raw}
  {$record->customFieldDisplayByKey($fieldId,'DESCRIPTION')|raw}
  // this doesn't exist

{{endforeach}}

Thanks.

  • Like 1
Link to post
Share on other sites
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular 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  

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

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 da

  • 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 post
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!

  • Like 1
Link to post
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}
{{endforeach}}

 

 

  • Like 1
Link to post
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

×
×
  • Create New...