Members

Note: You can use your Sitellite.org account here and vice versa.

Username

Password

Remember Login

Forgot your password?

Not a member? Click here to register

Template Binding

Home Page | All Pages | Recently Revised | Authors | Feeds |

If you're wondering how meta tags and other such elements get inserted into the head of your template output without your doing, it's through an XT feature called "tag binding".

Tag binding allows you to call a PHP function to "bind" or attach a piece of output (ie. additional tags or content) to tags within a template, without having to insert XT tags to specify that they should go there. You can even bind values to attributes of tags that don't necessarily have that attribute in the template itself. For example, the page_onload() function binds a value to the onload attribute of your HTML body tag, regardless of whether your body tag has an onload attribute specified in your template or not.

Tag binding is used primarily in the page_*() functions (ie. page_add_script(), page_add_meta(), page_add_link(), and page_add_style(), as well as page_onload(), page_onfocus(), etc.) to dynamically add links, meta tags, stylesheets, and Javascript to templates as needed (ie. a <link rel="alternate" /> for RSS feeds).

The relevant functions that do this magic are template_bind() and template_bind_attr() in the saf.XML.XT package. You can use them like this:


<?php

template_bind (
    '/html/head',
    '<link rel="alternate"... />'
);

template_bind_attr (
    '/html/body',
    'onload',
    'alert ("hello world!")'
);

?>

Revised on June 7, 2005 12:54 PM by admin

Back in time (1 more) | Linked from: Templates