jaeitee Posted March 7, 2015 Posted March 7, 2015 Could someone please share how I can generate an {if} statement around a custom field?{$record->customFieldDisplayByKey('distance')|raw}I'm trying to have it display content if the field has been filled in, and if the field has not been filled in I am attempting to have that whole block of HTML not display. I can't use {{if ($value=='distance')}} as the value of distance is a unique number.
opentype Posted March 7, 2015 Posted March 7, 2015 You actually just need to type:{{ if $record->customFieldDisplayByKey('distance') }} // Something {{ endif }}If that doesn’t work for that field, because it returns something even when empty, you can call the field directly.{{ if $record->field_XX }} // Something {{ endif }}XX is the unique ID of that field.
jaeitee Posted March 7, 2015 Author Posted March 7, 2015 Thank you very much @Ralf H. the second option worked perfectly!
jaeitee Posted March 11, 2015 Author Posted March 11, 2015 Alright, I have this working perfectly inside the Display Template, however whenever I try and add a custom field to the recordRow for a Listing Template I encounter errors.I've tried both:{{ if $record->customFieldDisplayByKey('distance') }} SHOW TEXT {{endif}}{{ if $record->field_22 }} SHOW TEXT {{ endif }}I've tried removing the following: {{foreach $row->customFieldsForDisplay('listing') as $fieldId => $fieldValue}} {{if $fieldValue}} {$fieldValue|raw} {{endif}} {{endforeach}}Then adding $record->customFieldDisplayByKey('distance') in to a foreach loop and still no luck.It seems I can't call the fields to the listing template, only to the display template.
jaeitee Posted March 11, 2015 Author Posted March 11, 2015 PS: Somehow this topic has made its way in to "product feedback" since it was first created
opentype Posted March 11, 2015 Posted March 11, 2015 In a listing template, use $row instead of $record. $row->customFieldsForDisplay('listing') is correct, but make sure that you have set each field to actually show in listing templates. That’s a per-field setting. If you have turned that off, the field won’t show.
Kirill N Posted March 11, 2015 Posted March 11, 2015 @Ralf H. Could you help me out in a similar topic please? http://community.invisionpower.com/topic/408430-if-statement-help-needed/
jaeitee Posted March 11, 2015 Author Posted March 11, 2015 A step closer, $row->customFieldDisplayByKey('distance') seems to work however it pulls the formatting from the Display Template box, opposed to the Listing Template box with custom formatting in the ACP.
opentype Posted March 11, 2015 Posted March 11, 2015 $row->customFieldDisplayByKey('distance') Try: $row->customFieldsForDisplay('listing')['distance']
Recommended Posts
Archived
This topic is now archived and is closed to further replies.