Difference between revisions of "How to use custom variables"

From JReviews Documentation
Jump to: navigation, search
Line 1: Line 1:
Custom Variables in PaidListings make it possible to charge for many other things that are not available by default.
+
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.
  
For example, you can charge for the [[How to add Inquiry Form to listing detail pages|Inquiry Form on listing detail page]]
+
To set custom variables, edit your pricing plans and in the '''Advanced''' tab add the variable name and variable value in this format:
  
 +
[[File:new-plan4.png]]
  
To make it available in your Listing Plan, add a variable in the '''Custom Variables''' text area like this:
+
To access the custom variables use this code:
  
 
<source lang="php">
 
<source lang="php">
inquiry|enabled
+
<?php echo $Paid->getVar('var1',$listing);?>
 
</source>
 
</source>
  
  
In this example '''inquiry''' is the variable name and '''enabled''' is its value.
+
==Simple example of creating conditionals in the theme files based on custom variables==
  
 +
Let's say you created 3 plans: '''Free''', '''Basic''' and '''Premium'''
  
In the detail.thtml file if you followed instructions in the article linked above, you will have this code that outputs the inquiry form:
+
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:
  
 
<source lang="php">
 
<source lang="php">
<?php echo $this->element('inquiry_widget');?>
+
plan_type|free
 
</source>
 
</source>
  
 +
In the Basic plan enter this:
  
 +
<source lang="php">
 +
plan_type|basic
 +
</source>
 +
 +
In the Premium plan enter this:
 +
 +
<source lang="php">
 +
plan_type|premium
 +
</source>
 +
 +
Then in the theme files (i.e. /listings/detail.thtml) you can create conditionals like this:
 +
 +
<source lang="php">
 +
<?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;?>
 +
</source>
 +
 +
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 on listings that whose owners purchased the Premium plan.
 +
 +
In the Premium plan you can add a custom variable like this:
 +
 +
<source lang="php">
 +
inquiry|enabled
 +
</source>
  
To make the inquiry form enabled only if the listing plan is purchased, check the value of your custom variable like this:
+
In the theme file of the listing detail page (/listings/detail.thtml) you can add this code:
  
 
<source lang="php">
 
<source lang="php">
 
<?php if ($Paid->getVar('inquiry',$listing) == 'enabled'): ?>
 
<?php if ($Paid->getVar('inquiry',$listing) == 'enabled'): ?>
<?php echo $this->element('inquiry_widget');?>
+
    <?php echo $this->element('inquiry_widget');?>
<?php endif;?>
+
<?php endif;?>
 
</source>
 
</source>
  
If the listing plan is not purchased, the variable will have no value and the inquiry form will not be displayed.
+
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 Inquery Form, you first need to disable the default inquiry functionality in JReviews Configuration, Listings tab. You need to set '''Enable Listing Inquiries''' to No.
  
This way you can charge for any part of the listing detail page using '''Custom Variables'''.
 
  
  

Revision as of 20:46, 20 November 2013

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 on listings that 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 Inquery Form, you first need to disable the default inquiry functionality in JReviews Configuration, Listings tab. You need to set Enable Listing Inquiries to No.