Jump to content

{if} statement for custom field?


jaeitee

Recommended Posts

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.

Link to comment
Share on other sites

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. 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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