sgimc 8 Posted February 4 Share Posted February 4 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. 1 Link to post Share on other sites
Owner Jimi Wikman 460 Posted February 4 Owner Share Posted February 4 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
sgimc 8 Posted February 4 Author Share Posted February 4 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! 1 Link to post Share on other sites
Owner Jimi Wikman 460 Posted February 5 Owner Share Posted February 5 Happy to help Link to post Share on other sites
sgimc 8 Posted February 9 Author Share Posted February 9 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}} 1 Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now