Difference between revisions of "How to use custom variables"

From JReviews Documentation
Jump to: navigation, search
 
(10 intermediate revisions by one other user not shown)
Line 1: Line 1:
Custom Variables in PaidListings make it possible to charge for many other things that are not available by default.
+
__TOC__
  
For example, you can charge for the [[How to add Inquiry Form to listing detail pages|Inquiry Form on listing detail page]]
+
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:
  
To make it available in your Listing Plan, add a variable in the '''Custom Variables''' text area like this:
+
[[File:new-plan4.png]]
 +
 
 +
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:
  
To make the inquiry form enabled only if the listing plan is purchased, check the value of your custom variable like 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 for listings whose owners purchased the Premium plan.
 +
 
 +
In the Premium plan you can add a custom variable like this:
 +
 
 +
<source lang="php">
 +
inquiry|enabled
 +
</source>
 +
 
 +
 
 +
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 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:
 +
 +
<source lang="php">
 +
if ($this->Paid->getVar('inquiry',$listing) == 'enabled') {
 +
    $this->inquiry($listing);
 +
}
 +
</source>
 +
 +
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.
  
This way you can charge for any part of the listing detail page.
+
[[Category:JReviews]]
 +
[[Category:PaidListings Addon]]
 +
[[Category:FAQ]]

Latest revision as of 20:33, 26 October 2016

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.