How to use custom variables

From JReviews Documentation
Jump to: navigation, search

Custom variables provide additional flexibility to your pricing plans. The variables are made available in the theme files so you can use them for customizations. For example, you can show/hide specific page elements based on the variables that are included in the plan.

To set custom variables, edit your pricing plans and in the Advanced tab add the variable name and variable value in this format:

New-plan4.png

To access the custom variables use this code:

<?php echo $Paid->getVar('var1',$listing);?>


Simple example of creating conditionals in the theme files based on custom variables

Let's say you created 3 plans: Free, Basic and Premium.

For each of those plans you can set a variable with the same name, but different value, for example:

In the Free plan enter this:

plan_type|free


In the Basic plan enter this:

plan_type|basic


In the Premium plan enter this:

plan_type|premium


Then in the theme files (i.e. /listings/detail.thtml) you can create conditionals like this:

<?php if ($Paid->getVar('plan_type',$listing) == 'free'): ?>
 
	This is a free listing.
 
<?php elseif ($Paid->getVar('plan_type',$listing) == 'basic'): ?>
 
	This is a basic listing.
 
<?php elseif ($Paid->getVar('plan_type',$listing) == 'premium'): ?>
 
	This is a premium listing.
 
<?php endif;?>


Listings that have the Free plan would output "This is a free listing.", listings that have the Basic Plan would output "This is a basic listing.", etc.

This way you can show/hide different parts of theme files based on the custom variable value.

Adding Inquiry Form to listings based on the custom variable

Let's say you want to show the inquiry form on listing detail pages, but only for listings whose owners purchased the Premium plan.

In the Premium plan you can add a custom variable like this:

inquiry|enabled


In the theme file of the listing detail page (/listings/detail.thtml) you can add this code:

<?php if ($Paid->getVar('inquiry',$listing) == 'enabled'): ?>
    <?php echo $this->element('inquiry_widget');?>
<?php endif;?>


This code would display the inquiry form only in listings whose owners purchased the plan that contains the inquiry custom variable. To use this approach for the Inquiry Form, you first need to disable the default inquiry functionality in JReviews Configuration, Listings tab. You need to set Enable Listing Inquiries to No.

If you want to show the inquiry button, instead of the embedded form as in the above example, then you would use a similar approach, but instead of editing the detail page theme file, you will edit the /views/helpers/widgets.php file and find the listingDetailButtons function. There you can add similar code around the line that outputs the inquiry button:

if ($this->Paid->getVar('inquiry',$listing) == 'enabled') {
    $this->inquiry($listing);
}

For this approach, you still need to enable inquiries via the configuration settings. And you can place the modified file in the overrides folder using the same /views/helpers/widgets.php path.