2
votes

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.

1
I'm going to leave this open for a bit in case anyone has any awesome advice, but basically i refreshed my Chrome tab after several minutes (like, after posting on forums everywhere) only to discover that adding a custom CSS class to an element in the template.htm file is picked up, and an anonymous function executed, when the custom CSS class name as used as a key value in the template_replace_values config object. So I suppose my question is answered since I can see some possibilities here, but again, any advice... - danjah
As a side note: staffid : getStaffId() should be staffid : getStaffId, if you're going to use that style. - deceze
well, the wiki is not up to date in some places - Thariama
@Deceze, feel free to add that as an answer if you like, because it was what tripped me up :P @Thariama, I'm slowly figuring this stuff out, so I'll most likely end up submitting a few wiki updates if they're wanted. - danjah

1 Answers

2
votes

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.