How to customize the layout of custom fields in Theme files

From JReviews Documentation
Revision as of 11:58, 2 November 2011 by Jreviews (Talk | contribs)

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

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/listings_blogview.thtml
  • /listings/listings_tableview.thtml
  • /listings/listings_thumbview.thtml
  • /modules/listings.thtml


Outputting a certain custom field

Outputs the field label

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


Outputs the field value

<?php echo $CustomFields->field('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_brand',$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_brand',$listing,false,false); ?>


An alternative solution is Using banner field type for custom field output.


Outputting a certain field group

Outputs a whole field group using the default output:

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

Just enter the correct Group Title. 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')));?>


Review custom fields

You can place review custom fields in these files:

  • /reviews/reviews.thtml (only for user reviews)
  • /modules/reviews.thtml


Outputs the field label

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


Outputs the field value

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


In /listings/detail.thtml for the editor review custom fields you can use this code:


Outputs the field label

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


Outputs the field value

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


Custom Field conditionals

Create conditional output based on field's value

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


Create conditional output for multiple select or checkbox custom fields based on some field value

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