Scf.ClientVar() Example

In this example, we add an SCF behavior, then attach the behavior to an HTML element using custom behavior settings.

Smartsite SXML CopyCode image Copy Code
<se:placeholder.addjavascript>
    $j.scf.behavior.add('TestBehavior', {
        attach: function(e,s,j){
            alert(s.isAnonymous);
        }
    });
</se:placeholder.addjavascript>

<button id="testButton">Go</button>
{scf.behavior.attach('#testButton', TestBehavior, 
    isAnonymous, scf.clientvar(user.isanonymous())
)}
Example Result CopyCode image Copy Code
<script type="text/javascript">
/*<![CDATA[*/
    $j.scf.behavior.add('TestBehavior', {
        attach: function(e,s,j){
            alert(s.isAnonymous);
        }
    });
    $j.scf.behavior.attach('#testButton', 'TestBehavior', {isAnonymous:true});
/*]]>*/
</script>