The Rule form: SUCCEED and FAIL actions

(0 votes, average 0 out of 5)

cham-succeed-1b

The SUCCEED and FAIL Actions forms are identical. The SUCCEED Actions get run when a rule succeeds (i.e. every part of the rule is set to Ignore or returns success/true), while the FAIL Actions get run if any part of the rule returns false.

1. Set TemplateStyle

This gives a drop-down list of all installed template styles. If you want to change template style as the result of the rule, select the new template style here.

2. Site Default Menu Item

This gives a list of all menu items on the site. Joomla allows you to set one menu item as the “Default” — that is, the menu item that will be used as the front page of your site when there’s no other page requested (e.g. http://www.example.com/). This control allows you to change which page is used as the default.

Obviously, if an inner page was being requested on your site, then this has no effect on which page is displayed, but it does change the link for the menu item selected (it will be set to "/" rather than its previous alias). This control is particularly useful when using different templates for different sub-domains, as it also allows you to set a different default page per sub-domain.

3. Active Menu Item

The “Active” menu item is the menu item that often gets highlighted in some way on the page, to indicate the “current” page. There are times however when you may want a menu item to be displayed as “Active” which does not actually correspond to the current page. One example of this is if you are making use of an off-screen (hidden) menu item. In this case you may wish for one of the existing main menu items to be highlighted instead.

Just use the drop-down to select which menu item should be displayed as “Active” as a result of the SUCCEED or FAIL action.

This feature depends on the module or template to display the menu correctly. The module or template displaying the menu must use the $menu object provided by Joomla as the data source for the displayed menu. This structure includes a variable indicating the active menu item, and that’s what Chameleon manipulates. If the module or template ignores this and recreates the menu directly from the database, or assumes that the current Itemid should be used as the Active menu item, then this feature has no effect.

The standard mod_mainmenu module for displaying menus in Joomla works correctly with this feature.

4. Unpublish Menus

This control allows you to selectively unpublish certain menu items as a result of the rule. Hold down the Ctrl key (Windows) or Cmd key (Macintosh) to make multiple selections. If you click on the name of a complete menu (e.g. “Example Pages Menu”) then all items inside that menu will be unpublished for the current page request.

The menu item is not actually unpublished in the database — the effect is simply that it won’t show up on any of the menus during the current page request.

Examples:

  • Hide a “Logout” menu item for anyone who is logged in
  • Hide the existing “Home” menu item when you are changing the Default menu item to a different one, perhaps based on sub-domain
  • Remove certain Virtuemart menu items when a certain combination of products is in the shopping cart.

Important note: Any SEF URLs that are found in normal content & modules, and pointing to the unpublished menu item may break depending on the SEF extension used. This is because Joomla’s standard SEF looks up the currently published menus in order to create the SEF version of the URL. Obviously, if you have dynamically unpublished the menu item, then Joomla won’t find the information required to create the URL. However, sh404SEF and AceSEF have been tested and do not have this problem.

5. Unpublish menu items where note... (from v2.29 on Joomla 2.5+)

This control unpublishes all menu items that have a given "Note" attached to them in the Menu Manager. This allows you to effectively make a group of menu items which will be unpublished as a result of a rule success or failure, based solely on the "Note" in the menu item.

Example:

  • On a multi-homed site (example.de and example.fr) there may be some menu items that should be disabled when viewing example.de, and some that should be disabled when viewing example.fr.
  • In the menu manager, add a "note" to all the German items saying "DE only", and a note on all the French items saying "FR only"
  • Make a Chameleon rule detecting domain "example.de" and "www.example.de"
  • In the Succeed action, "Unpublish menu items where note" "equals" "FR only"
  • In the Fail action, "Unpublish menu items where note" "equals" "DE only"
  • By doing this, all the French-only items will disappear from example.de, and all the German items will disappear from example.fr.

6. Edit menu items

This control allows you to edit various aspects of menu items, including title, browserNav (0, 1, 2) and any internal parameters prefixed with “param:”.

Use a new line for each menu item you wish to edit. Each line starts with the menu item id followed by a semicolon then a semicolon-separated list of parameters (see examples).

Substitutions

{orig} in any value is replaced by the existing value for that parameter.
{global:$xxx}, {session:xxx} and {env:xxx}: $GLOBALS, $_SESSION and $_ENV variables.

Note
As the menu routing has already taken place before any changes here are made, you cannot change the alias or path values.

Examples:

1. Set a new title for the home page and switch to a "list" layout instead of "blog" (Category page):

101; title=New Home; param:layout_type=list

2. Append today's date to a menu item:

in the PHP block:

global $todays_date;
$todays_date = date("Y-m-d");

in the Edit menu item block:

101; title={orig} - {global:$todays_date}

Attributes and parameters you can alter:

Standard attributes available for every menu item:

  • title
  • browserNav (0 is standard link, 1 is new window without navigation, 2 is new window with navigation)

"param" types depend on what sort of menu item you are editing. Some common parameters include:

  • param:menu-anchor_title (Link Title Attribute)
  • param:menu-anchor_css (Link CSS Style)
  • param:menu_image (Link Image)
  • param:menu_text (Add Menu Title; 0 = off, 1 = on)
  • param:page_title (Browser Page Title)
  • param:show_page_heading (Show Page Heading; "" for use global, 0 for no, 1 for yes)
  • param:page_heading (Page Heading)
  • param:pageclass_sfx (Page Class)
  • param:menu-meta_description
  • param:menu-meta_keywords
  • param:robots ("" for use global, or "index, follow", "index, nofollow", "noindex, follow", "noindex, nofollow")
  • param:secure (-1 = off, 1 = on, 0 = ignore)

Single article view parameter options:

  • param:show_title
  • param:link_titles
  • param:show_intro
  • param:info_block_position
  • param:show_category
  • param:link_category
  • param:show_parent_category
  • param:link_parent_category
  • param:show_author
  • param:link_author
  • param:show_create_date
  • param:show_modify_date
  • param:show_publish_date
  • param:show_item_navigation
  • param:show_vote
  • param:show_tags
  • param:show_icons
  • param:show_print_icon
  • param:show_email_icon
  • param:show_hits
  • param:show_noauth
  • param:urls_position

Blog-style category view:

  • param:layout_type
  • param:show_category_heading_title_text
  • param:show_category_title
  • param:show_description
  • param:show_description_image
  • param:maxLevel
  • param:show_empty_categories
  • param:show_no_articles
  • param:show_subcat_desc
  • param:show_cat_num_articles
  • param:show_cat_tags
  • param:page_subheading
  • param:num_leading_articles
  • param:num_intro_articles
  • param:num_columns
  • param:num_links
  • param:multi_column_order
  • param:show_subcategory_content
  • param:orderby_pri
  • param:orderby_sec
  • param:order_date
  • param:show_pagination
  • param:show_pagination_results
  • param:show_featured
  • param:show_title
  • param:link_titles
  • param:show_intro
  • param:info_block_position
  • param:show_category
  • param:link_category
  • param:show_parent_category
  • param:link_parent_category
  • param:show_author
  • param:link_author
  • param:show_create_date
  • param:show_modify_date
  • param:show_publish_date
  • param:show_item_navigation
  • param:show_vote
  • param:show_readmore
  • param:show_readmore_title
  • param:show_icons
  • param:show_print_icon
  • param:show_email_icon
  • param:show_hits
  • param:show_tags
  • param:show_noauth
  • param:show_feed_link
  • param:feed_summary

7. Unpublish Plugins (from v2.25 on Joomla 2.5+)

This control allows you to specify one or more plugins to disable (unpublish). It is able to unpublish any system plugins that appear after the "System – Chameleon" plugin, or almost any other plugin of any type that has not already run by the time Chameleon executes.

Examples:

  • Remove a "comments" plugin from all articles in a certain category
  • Remove the ability to search a certain content type (e.g. categories or contacts) on a particular domain name. This is possible because each search type is a plugin.
  • Stop the System Cache plugin from caching a certain page or set of pages with particular dynamic content

cham-succeed-2b

8-9. Cookies / Session Variables

These controls allow you to set session (short term) or Cookie (long term, up to 10 years) variables based on the results of the rule. There are 4 session variables (A-D) and 4 cookies (A-D). Each variable can be "set" or "unset", or you can unset all of them.

You get Chameleon to set a cookie or session variable in order to remember the result of this rule for next time. Then you can set up another rule to detect this cookie or session variable, and set a template accordingly.

Options:

  • Set Session variable A
  • Set Session variable B
  • Set Session variable C
  • Set Session variable D
  • Remove Session variable A
  • Remove Session variable B
  • Remove Session variable C
  • Remove Session variable D
  • Remove Session variables A-D
  • Set permanent cookie A
  • Set permanent cookie B
  • Set permanent cookie C
  • Set permanent cookie D
  • Remove permanent cookie A
  • Remove permanent cookie B
  • Remove permanent cookie C
  • Remove permanent cookie D
  • Remove permanent cookies A-D

Example:

  • Set a Session variable as a result of detecting a particular URL as a landing page (e.g. http://www.example.com/info?landing=1).
  • In the SUCCEED action, set Session variable A, and continue to the next rule.
  • In the 2nd rule, detect Session variable A, and in the SUCCEED action set a special template.
  • In this way, someone who visits the landing page will see the special template for the rest of their session, until they quit their browser or the Joomla session times out. If you want the new template to be used for that person forever, use a permanent cookie rather than a Session variable.

10. Run PHP

Use this box to run arbitrary PHP code as a result of SUCCESS or FAILURE. See the documentation for the Advanced PHP panel for more information on PHP programming.

11. Execution Flow (Next Action)

If there are more rules in the rule chain what should happen next? Sometimes you want to detect a particular condition then immediately set a template and not process any more rules. Other times you might want to continue processing more rules, in case another rule further down the line decides to set a different template or perform other actions.

Options:

  • Stop processing
  • Process next rule in chain
  • Redirect to another Joomla page, or external URL

If you choose to redirect, you can pick a Joomla page from the drop-down, or specify an external URL.

12. Redirect code

The redirections in (11) and the language redirections below are performed using HTTP codes 301/302/303/307. You can use this control to change which type of code will be used. This is very important for Search Engines and also for the correct operation of browser caches.

Which HTTP code should be used for any redirect?

301: The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use the returned URI.

302: The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.

303: The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. The new URI is not a substitute reference for the originally requested resource.

307: The requested resource resides temporarily under a different URI. Since the redirection MAY be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.

Take great care with 301 redirects as clients will cache the new destination URL and won’t even request the original URL but go directly to the one to which they were redirected the first time.

See the Chameleon Flow Diagram for more information about the execution flow in Chameleon.

cham-succeed-vm-b

cham-succeed-3b

cham-succeed-4b

13. VM Shopper Group

Force the Shopper Group to one of the listed shopper groups, regardless of the previous shopper group of the current user or guest. This is incredibly useful in combination with detecting the domain or GeoIP address of the user – it allows you to set up alternative currency/pricing associated with a particular shopper group, then base the shopper group on the domain the shopper is using, the browser language, or the GeoIP country of the user.

14. Page Title

Set the Page Title (the <title> tag in the <head> of the HTML document) here. You can use substitutions such as {title} (the previous title of the page before replacement), {metadescription} and {metakeywords} to use the values of these fields, as well as {global:$xxx}, {session:xxx} and {env:xxx} to insert values from the $GLOBALS, $_SESSION and $_ENV superglobal arrays.

15. MetaDescription

Set the Meta Description (the tag in the <head> of the HTML document) here. You can use substitutions such as {title} (the previous title of the page), {metadescription} and {metakeywords} to use the values of these fields, as well as {global:$xxx}, {session:xxx} and {env:xxx} to insert values from the $GLOBALS, $_SESSION and $_ENV superglobal arrays.

16. MetaKeywords

Set the Meta Keywords (the tag in the <head> of the HTML document) here. You can use substitutions such as {title} (the previous title of the page), {metadescription} and {metakeywords} to use the values of these fields, as well as {global:$xxx}, {session:xxx} and {env:xxx} to insert values from the $GLOBALS, $_SESSION and $_ENV superglobal arrays.

17. HTML Head Include (1 and 2)

This section allows you to add arbitrary CSS, JS, or include JS/CSS files in the <head> of your HTML document. This can be used to make subtle or major changes to the look or functionality of the page without having to use a whole new template. You can include up to two files/code snippets per Succeed action. You may make substitutions using {global:$xxx}, {session:xxx} and {env:xxx} to insert values from the $GLOBALS, $_SESSION and $_ENV superglobal arrays.

typeExampleFinal output in <head> of HTML document
CSS file xxx.css <link rel="stylesheet" href="/xxx.css" type="text/css" />
Raw CSS p.mystyle {text-weight: bold} <style type="text/css">
<!--
p.mystyle {text-weight: bold}
-->
</style>
JS file xxx.js <script type="text/javascript" src="/xxx.js"></script>
Raw HTML for header anything at all exactly as you typed it in

Examples:

  • Use the CSS feature to change the background image of a page depending on the domain
  • Use the Raw HTML feature to insert different Google Analytics codes on different pages of the site
  • Use the JS file feature to only add JS libraries to pages that actually need them

18. Language

(Multi-lingual sites only) Select a language here to force redirect the page to the equivalent in the language selected. This is equivalent to the user clicking on a language flag in the Language Selector module, so you need to have set up all the language associations just as you would for normal multi-lingual sites.

This feature is useful for forcing the site into a certain language when a particular domain is used. Using this feature you could force all traffic for domain mysite.fr into the French language equivalent of the site, or all views of pages in a different section of the site to their German equivalent.

19. Language Redirect Protocol and Language Redirect Domain

If you want the language to be set AND redirected to an alternative domain name (e.g. mysite.de) then you can enter the domain name and protocol here. This feature is intended to be used when you have several domains pointing to the same Joomla installation ("parked domains" in cPanel terminology). For example, your site may be set up with parked domains "mysite.fr" and "mysite.de", both pointing to the same Joomla installation. You could force all traffic from browsers set up in German but on mysite.fr over to the German equivalent on mysite.de. For the language redirect domain, you may make substitutions using {global:$xxx}, {session:xxx} and {env:xxx} to insert values from the $GLOBALS, $_SESSION and $_ENV superglobal arrays.

20. Find and Replace

Chameleon actions can perform a find-and-replace on any HTML code found in the <head>, <body> or entire html document once it has been rendered.

You are initially given two sets of find-and-replace fields. If you need more, then fill in the ones provided, save the Chameleon rule, and when you re-edit it you will be given two more sets of fields.

Note that when you find and replace text, that text may possibly match HTML code and tags. e.g. if you replace the word "table" with "chair", then HTML tables such as <table><tr><td>info</td></tr></table> will become <chair><tr><td>info</td></tr></chair> which will obviously break your HTML tables.

Any regex "search" expressions must include delimiters e.g. #search phrase#

Regex "replace" expressions can use $1-$n to match parenthesised expressions from the search regex.

You may make substitutions into the Find and Replace expressions using {global:$xxx}, {session:xxx} and {env:xxx} to insert values from the $GLOBALS, $_SESSION and $_ENV superglobal arrays.

Examples:

  • use tokens such as {latestproductversion} throughout your site, then use a Chameleon rule to search for that phrase and replace it with your latest product version number
  • use this as a last resort for removing unwanted JS includes from your page which you can't remove any other way
  • alter product names on your site for visitors coming from different countries (GeoIP)
  • change advertising slogans on your site based on referrer, GeoIP or the domain they are using to view the site
  • use the {globals:$xxx} system to dynamically alter the "replace" expression. e.g. if you want to replace token {the_date} on the site with the actual date, do this:

in the PHP box:

global $todays_date;
$todays_date = date("Y-m-d");

In the Find box: {the_date} In the Replace box: {global:$todays_date}

Last Updated on Wednesday, 15 July 2015 10:55