Difference between revisions of "PHP Based Formatting"

From JReviews Documentation
Jump to: navigation, search
Line 1: Line 1:
 
PHP Based Formatting for Custom Fields adds an incredible amount of flexibility to what you can do with the output of custom fields. With some basic knowledge of php programming you can start creating conditionals in no time to modify the behavior of any field based on different variables.
 
PHP Based Formatting for Custom Fields adds an incredible amount of flexibility to what you can do with the output of custom fields. With some basic knowledge of php programming you can start creating conditionals in no time to modify the behavior of any field based on different variables.
 +
 +
__TOC__
  
 
== Available PHP Classes and Variables ==
 
== Available PHP Classes and Variables ==
  
* $CustomFields - The JReviews CustomFields theme helper which lets you use the same methods described in [[How_to_customize_the_layout_of_custom_fields_in_Theme_files|How to customize the layout of custom fields in Theme_files]].
+
{| class="wikitable" cellpadding="0" cellspacing="0"
 
+
|-
* $User - The Joomla User object contains information about the current logged in user.
+
|$CustomFields || The JReviews CustomFields theme helper which lets you use the same methods described in [[How_to_customize_the_layout_of_custom_fields_in_Theme_files|How to customize the layout of custom fields in Theme_files]].
 
+
|-
$DB - The Joomla Database object allows you to query the database.
+
|$User || The Joomla User object contains information about the current logged in user.
 
+
|-
$Access - The JReviews Access class lets you quickly find out if a user has access to perform certain actions or determine if the user belongs to a specific user group.
+
|$DB || The Joomla Database object allows you to query the database.
 
+
|-
$name - The custom field name.
+
|$Access || The JReviews Access class lets you quickly find out if a user has access to perform certain actions or determine if the user belongs to a specific user group.
 
+
|-
$entry - The complete listing or review array depending on the location of the field.
+
|$name || The custom field name.
 
+
|-
$field - The array for the current custom field.
+
|$entry || The complete listing or review array depending on the location of the field.
 
+
|-
$fields - The array of all custom fields available for the entry.
+
|$field || The array for the current custom field.
 
+
|-
$value - A string or array with the current field values. Multiple option fields like checkboxes and multiple select will be arrays, while other fields will be strings. For fields without options (text, decimal, integer, etc.) the $value matches the $text variable below.
+
|$fields || The array of all custom fields available for the entry.
 
+
|-
$text - A string or array with the current field values. Multiple option fields like checkboxes and multiple select will be arrays, while other fields will be strings.
+
|$value || A string or array with the current field values. Multiple option fields like checkboxes and multiple select will be arrays, while other fields will be strings. For fields without options (text, decimal, integer, etc.) the $value matches the $text variable below.
 
+
|-
$image - A string or array with the current field option image name if one was assigned.
+
|$text || A string or array with the current field values. Multiple option fields like checkboxes and multiple select will be arrays, while other fields will be strings.
 
+
|-
$output - An array with the current output for the field.  
+
|$image || A string or array with the current field option image name if one was assigned.
 +
|-
 +
|$output || An array with the current output for the field.  
 +
|}
  
 +
== Examples ==
  
 +
=== Displaying the default output without changes ===
  
 +
This is the most basic output. It doesn't change the default output of the field
  
 +
<source lang="php"><?php return $output;?></source>
  
 +
== Hiding the field ==
  
 +
<source lang="php"><?php return false;?></source>
  
  

Revision as of 23:20, 25 October 2013

PHP Based Formatting for Custom Fields adds an incredible amount of flexibility to what you can do with the output of custom fields. With some basic knowledge of php programming you can start creating conditionals in no time to modify the behavior of any field based on different variables.

Available PHP Classes and Variables

$CustomFields The JReviews CustomFields theme helper which lets you use the same methods described in How to customize the layout of custom fields in Theme_files.
$User The Joomla User object contains information about the current logged in user.
$DB The Joomla Database object allows you to query the database.
$Access The JReviews Access class lets you quickly find out if a user has access to perform certain actions or determine if the user belongs to a specific user group.
$name The custom field name.
$entry The complete listing or review array depending on the location of the field.
$field The array for the current custom field.
$fields The array of all custom fields available for the entry.
$value A string or array with the current field values. Multiple option fields like checkboxes and multiple select will be arrays, while other fields will be strings. For fields without options (text, decimal, integer, etc.) the $value matches the $text variable below.
$text A string or array with the current field values. Multiple option fields like checkboxes and multiple select will be arrays, while other fields will be strings.
$image A string or array with the current field option image name if one was assigned.
$output An array with the current output for the field.

Examples

Displaying the default output without changes

This is the most basic output. It doesn't change the default output of the field

<?php return $output;?>

Hiding the field

<?php return false;?>