danjah
danjah

Reputation: 3059

How to create updating template variables in TinyMCE?

Following the straightforward 'full' example, and after reading the Wiki and searching the moxie forums for an answer, I've come up with naught so far. Basically, I'm trying to do what the wiki suggests is possible but when I supplement the example 'staffid' value with an anonymous function, the variable is not replaced.

template_replace_values : {
    username : "Jack Black",
    staffid : function(e){
        var staffidInput = yd.get('staffidInput');
        return (staffidInput !== null)? staffidInput.value : '0178678';
    }
}

...but it didn't work, so I then defined the function before instantiating tinyMCE:

    function getStaffId(){

        var staffidInput = yd.get('staffidInput');
        alert('template_replace_values processed, staffidInput: '+staffidInput);
        return (staffidInput !== null)? staffidInput.value : '555555';

    }
... more instantiation code...
        template_replace_values : {
            username : "Jack Black",
            staffid : getStaffId()
        }

...and the value only picked up the first time, its never updated as the wiki suggests (whenever a 'cleanup' procedure is performed). I'm guessing something somewhere is undefined and not throwing an error because 'getStaffId' in my second, mostly successful attempt would be undefined in the tinyMCE iframe document context, I think..?

My aim is to have variables which can be configured in the template preview screen and also after the template has been inserted.

Upvotes: 2

Views: 2888

Answers (1)

deceze
deceze

Reputation: 522081

Instead of this:

template_replace_values : {
    username : "Jack Black",
    staffid : getStaffId()
}

this:

template_replace_values : {
    username : "Jack Black",
    staffid : getStaffId
}

getStaffId() executes the function and uses its return value as value for staffid, getStaffId uses the function as value for staffid.

Upvotes: 2

Related Questions