Jump to content

Recommended Posts

Posted

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.

Posted

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' )"}

 

Posted

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!

Posted
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?

 

Posted

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}}

 

  • 4 months later...
Posted
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' );}}

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...