Discover Data Available in Templates

To render a view in a controller, it's necessary to specifically set the variables that will be made available to that view. For example in listing lists and listing detail pages, the $listings and $listing variables are set.

When making customizations to a template, you may wonder which variables are present, because not all variables are present in all templates.

Showing View Variables

You can quickly take a peek at the variables in the view by adding the debug code snippets below, then reloading the page.

The dump & die function shows the data and immediately stops execution of the page

// For JReviews 3.x and earlier use dd instead of fwd_dd
<?php fwd_dd($this->viewVars); ?>

The print method shows the data and continues

<?php prx($this->viewVars); ?>

When there is a lot of data in the view, the dd method makes it easier to visualize the data.

Using the dd method in the listing detail page, may show something like this, which varies depending on the Add-ons you are using:

array:22 [▼
  "show_map" => false
  "search_itemid" => "269"
  "themeDebug" => false
  "addonPosition" => array:6 [▶]
  "captcha" => ""
  "mapSettings" => array:4 [▶]
  "address_fields" => array:4 [▶]
  "geo_fields" => array:4 [▶]
  "map_locale" => "en"
  "listing" => array:18 [▶]
  "crumbs" => array:3 [▶]
  "extension" => "com_content"
  "editor_review" => []
  "reviews" => array:2 [▶]
  "review_fields" => array:1 [▶]
  "review" => array:5 [▶]
  "formTokenKeys" => array:4 [▶]
  "listing_id" => "313"
  "listing_type_id" => "8"
  "listing_owner_id" => "33"
  "resources" => array:2 [▶]
  "resourceTypes" => array:2 [▶]
]

The keys in the array are avaible directly as variables on the template. So you can access the listing data through the $listing variable, and of course directly as $this->viewVars['listing'].

Of course you can use any of the data in the view as you see fit to customize your templates. Just keep in mind that the available data and names may change with future updates.

Listing Variables

In templates where the listing variable is available, you can of course create all sorts of logic using this data or output the data in many different ways. Although you can easily see all the listing data if you use the dump approach mentioned above, below you can find a non-exhaustive list of specific listing variables you can use.

Data Variable
Listing ID $listing['Listing']['listing_id']
Listing Title $listing['Listing']['title']
Listing Alias $listing['Listing']['slug']
Listing URL $listing['Listing']['url']
Listing summary $listing['Listing']['summary']
Listing description $listing['Listing']['description']
Summary + Description $listing['Listing']['text']
Media count $listing['Listing']['media_count']
Photo count $listing['Listing']['photo_count']
Video count $listing['Listing']['video_count']
Audio count $listing['Listing']['audio_count']
Attachment count $listing['Listing']['attachment_count']
Number of visits $listing['Listing']['hits']
Created date $listing['Listing']['created']
Modified date $listing['Listing']['modified']
Category ID $listing['Category']['cat_id']
Category title $listing['Category']['title']
Category alias $listing['Category']['slug']
Directory ID $listing['Directory']['dir_id']
Directory Title $listing['Directory']['title']
Listing Type ID $listing['ListingType']['listing_type_id']
Listing author's ID $listing['User']['user_id']
Listing author's real name $listing['User']['name']
Listing author's username $listing['User']['username']
Listing author's email $listing['User']['email']
User rating $listing['Review']['user_rating']
Number of user ratings $listing['Review']['user_rating_count']
Number of user reviews $listing['Review']['user_review_count']
Editor rating $listing['Review']['editor_rating']
Number of editor ratings $listing['Review']['editor_rating_count']
Number of editor reviews $listing['Review']['editor_review_count']
Main Media URL $listing['MainMedia']['media_info']['image']['url']
Favorite Count $listing['Favorite']['favored']
Claim Status $listing['Claim']['approved']

Listing Type

If you have the listing type ID, you can use it to get the listing type title

<?php
$listingTypeId = $listing['ListingType']['listing_type_id'];

$listingType = $this->listing_type->getById($listingTypeId);

echo $listingType['ListingType']['title'];
?>

In the listing detail page, where the listing type is pre-determined, you can use this shortcut:

<?php echo $this->listing_type->title;?>