mcsg Posted February 4, 2021 Share Posted February 4, 2021 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. Link to comment Share on other sites More sharing options...
bfarber Posted February 4, 2021 Share Posted February 4, 2021 Inside the loop you have $fieldId, so you could do this: {{$field = \IPS\cms\Fields<database_id>::load( $fieldId );}} Label: {$field->_title} Description: {$field->_description} Alternatively, they're just language strings with the key "content_field_<field_id>" and "content_field_<field_id>_desc" so you could use Label: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $fieldId )"} Description: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $fieldId . '_desc' )"} Link to comment Share on other sites More sharing options...
mcsg Posted February 4, 2021 Author Share Posted February 4, 2021 Fantastic. Thank you @bfarber! @Jimi Wikman had come up with a nice workaround of setting the custom field listing type to {$label} and using Label: {$record->customFieldDisplayByKey($fieldId,'listing')|raw} I think he'll also be happy to see this direct method. Thanks again! Link to comment Share on other sites More sharing options...
mcsg Posted February 4, 2021 Author Share Posted February 4, 2021 1 hour ago, bfarber said: Inside the loop you have $fieldId, so you could do this: {{$field = \IPS\cms\Fields<database_id>::load( $fieldId );}} Label: {$field->_title} Description: {$field->_description} Alternatively, they're just language strings with the key "content_field_<field_id>" and "content_field_<field_id>_desc" so you could use Label: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $fieldId )"} Description: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $fieldId . '_desc' )"} @bfarber Tried the above and $fieldId is the template key, not the numbered ID of the field. So in the example: {{foreach $record->customFieldsForDisplay('display_top') as $fieldId => $fieldValue}} custom field template key: {$fieldId} custom field data: {$record->customFieldDisplayByKey($fieldId,'processed')|raw} {{endforeach}} Will result in: custom field template key: programs_key custom field data: programs data custom field template key: note_key custom field data: These are the notes custom field template key: salary_key custom field data: 40000 How do we get the FIELD ID number for each of the custom fields? Link to comment Share on other sites More sharing options...
bfarber Posted February 5, 2021 Share Posted February 5, 2021 {{$field = \IPS\cms\Fields<database_id>::load( $fieldId, 'field_key' );}} Link to comment Share on other sites More sharing options...
mcsg Posted February 9, 2021 Author Share Posted February 9, 2021 Thank you @bfarber. To sum up in case others come across this. In order to display a Custom Field information in a Pages Database, determine the Pages <database_id> (a number) and use the following template code. In this case, I am iterating over the custom fields that are marked to display above the content ('display_top') in the DatabaseTemplates > RecordDisplay > Record template. {{foreach $record->customFieldsForDisplay('display_top') as $fieldId => $fieldValue}} <!-- fieldId is the field template identifier --> {{$field = \IPS\cms\Fields<database_id>::load( $fieldId, ‘field_key' );}} <!-- gets the field object --> Template Code: {$fieldId}<br/> Field ID: {$field->_id}<br/> Label: {$field->_title}<br/> Desc: {$field->_description}<br/> OR<br/> Label: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $field->_id )"}<br/> Desc: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $field->_id . '_desc' )"}<br/> Value: {$record->customFieldDisplayByKey($fieldId,'processed')|raw} {{endforeach}} christopher-w 1 Link to comment Share on other sites More sharing options...
Iskander001 Posted June 17, 2021 Share Posted June 17, 2021 On 2/10/2021 at 2:46 AM, mcsg said: Thank you @bfarber. To sum up in case others come across this. In order to display a Custom Field information in a Pages Database, determine the Pages <database_id> (a number) and use the following template code. In this case, I am iterating over the custom fields that are marked to display above the content ('display_top') in the DatabaseTemplates > RecordDisplay > Record template. {{foreach $record->customFieldsForDisplay('display_top') as $fieldId => $fieldValue}} <!-- fieldId is the field template identifier --> {{$field = \IPS\cms\Fields<database_id>::load( $fieldId, ‘field_key' );}} <!-- gets the field object --> Template Code: {$fieldId}<br/> Field ID: {$field->_id}<br/> Label: {$field->_title}<br/> Desc: {$field->_description}<br/> OR<br/> Label: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $field->_id )"}<br/> Desc: {expression="\IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . $field->_id . '_desc' )"}<br/> Value: {$record->customFieldDisplayByKey($fieldId,'processed')|raw} {{endforeach}} {{$field = \IPS\cms\Fields<database_id>::load( $fieldId, ‘field_key' );}} In above mentioned line in real example should it be like this: {{$field = \IPS\cms\Fields12::load( $fieldId, ‘field_key' );}} Link to comment Share on other sites More sharing options...
Recommended Posts