JReviews logo Docs
Menu
Version

Discover Data Available in Templates

Learn how to discover and use variables available in JReviews templates, including listing data, review data, and other view variables.

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 available 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']

Early Access Blade Template Variables

Early Access Only
This section applies to custom field Blade templates and Early Access theme overrides when the Early Access listing detail page is enabled.

When using Blade templates for custom field formatting (Early Access), the $listing and $comment variables are Eloquent model instances, not arrays. Use arrow syntax to access properties.

Listing Model Properties

Data Variable
Listing ID $listing->id
Listing Title $listing->title
URL Alias $listing->alias
Summary $listing->summary
Description $listing->description
Listing URL $listing->url
Category URL $listing->category_url
Category ID $listing->cat_id
Category Title $listing->category_title
Listing Type ID $listing->listing_type_id
Status $listing->status
Featured $listing->featured
Hot Badge $listing->hot
New Badge $listing->recent
Views $listing->views
Created Date $listing->created
Modified Date $listing->updated
Publication Date $listing->publication_date
Expiration Date $listing->expiration_date
Owner ID $listing->owner_id
Owner Name $listing->owner_name
Owner Email $listing->owner_email
Listing Email $listing->email
Meta Description $listing->metadesc
Meta Keywords $listing->metakey
Map Marker Icon $listing->marker_icon

Listing Helper Methods

Method Description
$listing->isPublished() Check if listing is published
$listing->isUnpublished() Check if listing is unpublished/draft
$listing->isPending() Check if listing is pending moderation
$listing->isDraft() Check if listing is a draft
$listing->isTrashed() Check if listing is trashed
$listing->isScheduled() Check if listing is scheduled for future publication
$listing->isExpired() Check if listing has expired
$listing->statusLabel() Get human-readable status label
$listing->allowsRatings() Check if listing type allows ratings
$listing->allowsComments() Check if listing type allows comments
$listing->hasMainPhoto() Check if listing has a main photo
$listing->hasCoverPhoto() Check if listing has a cover photo
$listing->hasLogoPhoto() Check if listing has a logo photo
$listing->hasVisibleCover() Check if cover photo should be visible
$listing->hasVisibleLogo() Check if logo photo should be visible
$listing->hasGalleryPhotos() Check if listing has gallery photos
$listing->getPhotos() Get photos collection
$listing->getVideos() Get videos collection
$listing->getAudio() Get audio collection
$listing->getAttachments() Get attachments collection
$listing->getGalleryPhotos() Get gallery photos collection

Custom Field Methods

Method Description
$listing->getFieldValue('jr_fieldname') Get raw field value
$listing->getFieldText('jr_fieldname') Get field text (converts options to labels)
$listing->getFieldTextString('jr_fieldname') Get field text as comma-separated string
$listing->getField('jr_fieldname') Get field configuration object
$listing->getFields() Get all fields collection
$listing->getNonEmptyFields() Get non-empty fields collection
$listing->getSearchableFields() Get searchable fields collection
$listing->getFieldOptionImage('jr_fieldname') Get option image filename

These methods also work on $comment for review custom fields.

Listing Relationships

Relationship Description
$listing->user User model (listing owner)
$listing->listing_type ListingType model
$listing->category Category model (Joomla only)
$listing->directory Directory model
$listing->aggregates Rating aggregates
$listing->ratings Ratings collection
$listing->comments Comments collection
$listing->media Media collection
$listing->favorites Favorites collection
$listing->field_data Custom field data
$listing->mainPhoto Main photo Media model
$listing->coverPhoto Cover photo Media model
$listing->logoPhoto Logo photo Media model

Working with Photo Accessors

The mainPhoto, coverPhoto, and logoPhoto accessors return Media model instances. You can access various properties on these models:

Property Description
->url URL to the media item
->original Original image URL
->id Media ID
->title Media title
->description Media description
->owner_name Owner's name

Usage Examples

{{-- Display main photo with fallback --}}
@if ($listing->hasMainPhoto())
    <img src="{{ $listing->mainPhoto->url }}" alt="{{ $listing->title }}">
@endif

{{-- Display cover photo --}}
@if ($listing->hasVisibleCover())
    <div class="cover-image" style="background-image: url('{{ $listing->coverPhoto->url }}')"></div>
@endif

{{-- Display logo photo --}}
@if ($listing->hasVisibleLogo())
    <img src="{{ $listing->logoPhoto->url }}" alt="{{ $listing->title }} logo" class="logo">
@endif

Comment/Review Model Properties

Data Variable
Comment/Review ID $comment->id
Title $comment->title
Comment Text $comment->comment
Rating $comment->rating
Status $comment->status
Comment Type $comment->comment_type
Review URL $comment->url
Created Date $comment->created
Modified Date $comment->modified
Owner ID $comment->owner_id
Owner Name $comment->owner_name
Owner Email $comment->owner_email
Listing ID $comment->listing_id
Owner Reply Text $comment->owner_reply_text
Owner Reply Approved $comment->owner_reply_approved
Owner Reply Date $comment->owner_reply_created

Comment Helper Methods

Method Description
$comment->isPublished() Check if comment is published
$comment->isUnpublished() Check if comment is unpublished
$comment->isPendingModeration() Check if comment is pending moderation
$comment->isTrashed() Check if comment is trashed
$comment->isEditorComment() Check if this is an editor review
$comment->isUserComment() Check if this is a user review
$comment->hasPublishedOwnerReply() Check if has published owner reply
$comment->hasOwnerReplyPendingModeration() Check if owner reply is pending
$comment->statusLabel() Get human-readable status label
$comment->getPhotos() Get photos collection
$comment->getVideos() Get videos collection
$comment->getAudio() Get audio collection
$comment->getAttachments() Get attachments collection

Comment Relationships

Relationship Description
$comment->user User model (comment author)
$comment->listing Parent Listing model
$comment->listing_type ListingType model
$comment->media Media collection
$comment->ratings Ratings collection
$comment->field_data Custom field data

For complete documentation on Blade template formatting, see the Custom Field PHP Formatting guide.

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;?>