Difference between revisions of "JReviews Code Overrides"

From JReviews Documentation
Jump to: navigation, search
Line 16: Line 16:
  
  
== Modifying theme files in the overrides folder ==
+
== How to create a custom theme ==
  
 +
 +
*Read the [[How does the JReviews Theme Engine work]]
 
*Read the [[Default theme overview]] to learn the file structure
 
*Read the [[Default theme overview]] to learn the file structure
*Create a theme folder inside the overrides folder:
+
*Create a "jreviews_overrides" folder inside {site_root}/templates/
 +
*Create a theme folder inside the jreviews_overrides folder like this:
 
**<span style="color: blue">{site_root}/templates/jreviews_overrides/views/themes/'''mytheme'''</span>
 
**<span style="color: blue">{site_root}/templates/jreviews_overrides/views/themes/'''mytheme'''</span>
**Even if you want to modify the theme files from the /default theme, it is better to create a custom theme name in the overrides
+
**'''Important''' - your custom theme must have a unique name, don't name it the same as one of the existing themes.
 
+
*Create a themeInfo.xml file which will contain the information regarding the theme. You can copy the file from Compact theme and adjust the values (<name> and <title> most importantly)
*Copy the '''/theme_images''' folder with all its images from the default theme folder to your custom theme <span style="color: blue">{site_root}/templates/jreviews_overrides/views/themes/mytheme'''/theme_images'''</span>
+
*JReviews will always look for images in your custom theme, so copy the '''/theme_images''' folder with all its images from the default theme folder to your custom theme <span style="color: blue">{site_root}/templates/jreviews_overrides/views/themes/mytheme'''/theme_images'''</span>
*If you modify the css files you'll also need to copy the '''/theme_css/images''' folder to the custom theme
+
*If you will have css files you'll also need to copy the '''/theme_css/images''' folder to the custom theme
 
*Copy the theme files that you want to modify from the /default theme and make sure you use the same folder structure, for example:
 
*Copy the theme files that you want to modify from the /default theme and make sure you use the same folder structure, for example:
 
**If you want to modify the /themes/default'''/listings/detail.thtml''' file, create a copy like this:
 
**If you want to modify the /themes/default'''/listings/detail.thtml''' file, create a copy like this:

Revision as of 15:52, 18 August 2011


JReviews' code override functionality allows you to override any file located in the JReviews application folder at:

  • /components/com_jreviews/jreviews/


Why use the complete overrides functionality

The most common way to upgrade a component in Joomla is to uninstall it and then re-install it. This means that any code changes you might have made to the core files of the components could be lost if you don't have a back-up; it is also more difficult to keep track of the files that you've customized. With the code override functionality you can place your customized files in a folder outside of the JReviews component to keep all your customizations in one place and safe from upgrade losses. Of course you still need to check for file differences when there's an upgrade, because there might be bug fixes in your modified files, but now you can easily keep track of which files to check.

How do I use this capability?

Easy! Just create a new folder in the templates folder of your Joomla installation called "jreviews_overrides". This folder matches the jreviews folder inside com_jreviews so that:

  • {site_root}/templates/jreviews_overrides/ = /components/com_jreviews/jreviews/


How to create a custom theme

  • Read the How does the JReviews Theme Engine work
  • Read the Default theme overview to learn the file structure
  • Create a "jreviews_overrides" folder inside {site_root}/templates/
  • Create a theme folder inside the jreviews_overrides folder like this:
    • {site_root}/templates/jreviews_overrides/views/themes/mytheme
    • Important - your custom theme must have a unique name, don't name it the same as one of the existing themes.
  • Create a themeInfo.xml file which will contain the information regarding the theme. You can copy the file from Compact theme and adjust the values (<name> and <title> most importantly)
  • JReviews will always look for images in your custom theme, so copy the /theme_images folder with all its images from the default theme folder to your custom theme {site_root}/templates/jreviews_overrides/views/themes/mytheme/theme_images
  • If you will have css files you'll also need to copy the /theme_css/images folder to the custom theme
  • Copy the theme files that you want to modify from the /default theme and make sure you use the same folder structure, for example:
    • If you want to modify the /themes/default/listings/detail.thtml file, create a copy like this:
      • {site_root}/templates/jreviews_overrides/views/themes/mytheme/listings/detail.thtml
    • Do not copy all files from /default theme, only the ones you plan to modify
  • Important: For JReviews to recognize new files, you must click on 'Clear File Registry' link in JReviews Administration:

FileRegistry.png

  • Next, go to JReviews Configuration, tab 'General' and select your custom theme from the dropdown
  • When you make modifications to the theme files, but the modifications aren't visible on the site, you probably need to clear the browser's cache to see the changes (in some cases it will be necessary to clear cache in JReviews and Joomla also)


Notes about modifying Compact or Dark theme

  • These two themes are variations of the default theme and don't contain all files as /default theme (the same as your custom theme should)
  • If you use one of those themes and want to modify it, you can use it as a base for your custom theme. Copy whole /themes/compact or /themes/dark folder into the overrides folder and rename it to "mytheme"

Modifying JReviews core files

  • It is recommended not to make too many modifications to the JReviews core files, in order to make future upgrades easier; but you can do them the same way as when modifying theme files
  • For example, if you want to override a controller (i.e. listings_controller.php), it would look like this:
    • {site_root}/templates/jreviews_overrides/controllers/listings_controllers.php


The framework will always check in the JReviews_overrides folder first to see if the file is there and if found it will use it instead of the core file.

Keep in mind that anytime you add a file to the overrides folder you need to clear the File Registry in the JReviews administration. Doing this allows JReviews to recognize the new file. Otherwise it will continue reading the file from the main component folder.

What happens with modified files when JReviews is upgraded

Your modified files in the overrides folder will not be deleted when JReviews is upgraded, but you will need to update those modified files if they are changed in new version of JReviews. Read What happens with modified files when JReviews is upgraded