How to customize the layout of custom fields in Theme files

From JReviews Documentation
Revision as of 22:30, 10 July 2018 by Jreviews (Talk | contribs) (Outputting a certain field group)

Jump to: navigation, search

To simplify the initial setup of JReviews, there's a default output of custom fields for both listings and reviews. If you want to customize them, you can hide (not unpublish) the fields from both list and detail views in the Fields Manager, and place the fields where you want them in the theme files. If you decide to use any of the methods to output an entire field group, then you must also remove the code that outputs the default layout for the custom fields from the theme file.

Besides using custom code for custom fields in the theme files, it is possible to customize the field output using the Banner field type.

Custom field placement also allows to use fields in javascript code for Google Maps and other scripts you may want to use.

Listing custom fields

The following code works in these files:

  • /listings/detail.thtml
  • /listings/detail_compact.thtml
  • /listings/detail_tabs.thtml
  • /listings/detail_header.thtml
  • /listings/listings_blogview.thtml
  • /listings/listings_blogview_compact.thtml
  • /listings/listings_tableview.thtml
  • /listings/listings_thumbview.thtml
  • /listings/listings_masonry.thtml
  • /modules/listings.thtml
  • /modules/listings_slideshow.thtml
  • /modules/listings_vertical.thtml

Outputting a certain custom field

In all code examples below replace jr_fieldname with the name of the field that you want to output.

Outputs the field label

This code will output the label of the field where you place the code in the theme file:

<?php echo $CustomFields->label('jr_fieldname',$listing); ?>


Outputs the field value text

This code will output the text of the field value where you place the code in the theme file:

<?php echo $CustomFields->field('jr_fieldname',$listing); ?>


Outputs the field value

If you have a custom field with field options, this code will output the value of the field as it is referenced in the database:

<?php echo $CustomFields->fieldValue('jr_fieldname',$listing); ?>


Get field text without click2search or output re-format

You can also have a bit more control of the output by using additional parameters when you call the display method: $CustomFields->field($name, &$element, $click2search = true, $outputReformat = true)

The example below calls the brand field and turns off click2search and outputreformat advanced options:

<?php echo $CustomFields->field('jr_fieldname',$listing,false,false); ?>


Get text of selected option for select list with images

If you have a select field with images associated to options and want to get the field text for the selected option, use this code:

<?php echo $CustomFields->fieldText('jr_fieldname',$listing,false,false); ?>


Outputting a certain field group

If you want to use any of the methods below, then you must also remove the code (below) that outputs the default field layout from the theme file.

<?php echo $CustomFields->displayAll($listing,'content');?>

Outputs a whole field group using the default output:

<?php echo $CustomFields->displayAll($listing,'content','group-name');?>


Replace group-name with the name of the field group that you want to output. You can use this to put different groups in different tabs when combined with a tabs plugin.

Outputs multiple field groups:

<?php echo $CustomFields->displayAll($listing,'content', array('includeGroups' => array('group-name1', 'group-name2')));?>


Outputs all field groups except specified:

<?php echo  $CustomFields->displayAll($listing,'content', array('excludeGroups' => array('group-name1', 'group-name2')));?>

When using this approach to output field groups, you also need to remove the default code that outputs the custom fields in the listing detail page to avoid the output from being duplicated. Below is the code that outputs the standard fields layout:

<?php echo $CustomFields->displayAll($listing,'content');?>

Review custom fields

You can place review custom fields in these files:

  • /reviews/review_layout.thtml
  • /reviews/review_list_layout.thtml
  • /modules/reviews.thtml

Outputs the field label

This code will output the text of the field value where you place the code in the theme file:

<?php echo $CustomFields->label('jr_fieldname',$review); ?>


Outputs the field value text

This code will output the text of the field value where you place the code in the theme file:

<?php echo $CustomFields->field('jr_fieldname',$review); ?>


Custom Field conditionals

If you want to output certain code only if the specific custom field isn't empty, you can use this code:

<?php if($CustomFields->field('jr_fieldname',$listing,false,false) != ''):?>
  <!-- Add your code here-->
<?php endif;?>


If you want to output certain code only if the specific custom field has a specific value, you can use this code:

<?php if($CustomFields->field('jr_fieldname',$listing,false,false) == 'some-value'):?>
  <!-- Add your code here-->
<?php endif;?>


If you have a multiple select or checkbox type of custom field and you want to check if it has a specific value, use this code:

<?php if (in_array('some-value', $CustomFields->fieldValue('jr_fieldname',$listing))): ?>
  <!-- Add your code here-->
<?php endif; ?>