Skip to content

Template by AJAX

swirtSJW edited this page Nov 17, 2013 · 3 revisions

TemplateIt makes it easy to load any of your completely populated templates by AJAX. There are two methods to do this:

  1. Load the temlpate contents by ajax when needed and toss onto page based on screen state.

  2. Load the template by simply executing a javascript function so you can load the template into a js variable and do with it whatever you would like

In either case, the template is only loaded by AJAX the first time and is pulled from memory the next time, unless a 'fresh' option is set

Method 1 : AJAX load and toss based on screen state

Method 1 consists of either a client side approach OR a server side approach. Use one or the other, not both.

On the client side (javascript) it would look like this:

tossTemplateAjax (sTemplateNameAJX, aStatesAJX, sTargetIDsAJX);

sTemplateNameAJX - string of the full name of the template (the filename without the .tpl.php)

aStatesAJX - an array of screen states that this template should be tossed in. [tablet, wide] would cause the template to be tossed on the page in both the tablet and wide states.

sTargetIDsAJX - is the target id of the container where the contents of this template should be tossed.

-OR-

On server side (php) it would look like this:

<?=templateToss($sTemplateName, $sStatesToToss, $sTargetID, TRUE ); ?>

$sTemplateName - string of the full name of the template (the filename without the .tpl.php)

$sStatesToToss - comma separated string of screen states that this template should be tossed in. 'tablet, wide' would cause the template to be tossed on the page in both the tablet and wide states.

$sTargetID - is the container target id it should toss into

TRUE - is the AJAX flag that tells it to use ajax to load the template.

Method 2 : Load the template by simply executing a javascript function (this method is not available yet)

This method allows you to control the timing or events that trigger the AJAX load and the output all from within your custom javascript.

var someVariable = loadTemplateAjax (sTemplateNameAJX, bFresh);

sTemplateNameAJX - string of the full name of the template (the filename without the .tpl.php)

bCached - boolean - true causes the template to always load by AJAX each time it is called (not from cache), false causes it to only be loaded by AJAX the first time, then loaded from javascript storage (cache) on subsequent calls. (default: false)