Using System Settings

[[++jquery_load:eq=`0`:then=``:else=`
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/[[++jquery_version:default=`1.7.1`]]/jquery.min.js"></script>
`]]
[[++jquerytools_load:eq=`0`:then=``:else=`
<script type="text/javascript" src="//cdn.jquerytools.org/[[++jquerytools_version:default=`1.2.6`]]/all/jquery.tools.min.js"></script>
`]]

Explanation

[[++jquery_load:eq=`0`:then=``:else=`DO SOMETHING`]]
[[++jquerytools_load:eq=`0`:then=``:else=`DO SOMETHING`]]
  • » Check for the existence of a System Setting: jquery_load, jquerytools_load
  • » If found check its value to see if it is disabled
  • » If the System Setting does not exist or is set to disabled an empty string is returned
  • » Otherwise the else clause is executed
<script type="text/javascript"
 src="//ajax.googleapis.com/ajax/libs/jquery/[[++jquery_version:default=`1.7.1`]]/jquery.min.js"
></script>
  • » Check for the jquery_version System Setting
  • » If it exists, insert its value in the placeholder
  • » Else default to version 1.7.1

Output



Comments

As you may have noticed, the jQuery version which was placed in the page was 1.7.2 and not the default 1.7.1 which was the "current" version when the site went live. This is due to existence of a System Setting which is used to override the default value.

Techniques such as this, allows a single Chunk to be used across multiple Templates and/or Resources in order to update various sections of the site, while leaving others set to the default value.

Most applications would simply place this in the header of a Template and allow the inclusion of the respective library to be managed site-wide - wherever the Template is in use.

Other applications may have very little need of the jQuery library, and therefore the inclusion of a Chunk on those pages may prove more beneficial.

Using a simple Chunk

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/[[+jquery_version:default=`1.7.1`]]/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jquerytools.org/[[+jquerytools_version:default=`1.2.6`]]/all/jquery.tools.min.js"></script>

Explanation

  • » [[++jquery_version:default=`1.7.1`]] becomes [[+jquery_version:default=`1.7.1`]]
  • » Essentially, this simple change makes jquery_version a Placeholder

As this method may be considered more premeditated, the check for it being "desired" in the current page has been removed.

Chunk Call - jQuery Version

[[$jQueryLoaderRuntime?jquery_version=`1.4.2`]]

Chunk Output



Chunk Call- both changed

[[$jQueryLoaderRuntime?jquery_version=`1.4.4`&jquerytools_version=`1.2.4`]]

Chunk Output



Final Comments

These techniques can be used in a wide array of application, such as layout, targeted css, SEO, images, etc. In many situations similar implementations are the reason the page source changes upon every load. Experiment and see what you can come up with.