# Pasting TemplateBox with a Dynamic argument

Ok, this is pretty specific...

The objective is to use a TemplateBox to format something that is programatically inserted with NotebookWrite. That thing which is inserted is some dynamic control, an OpenerBox. So, for example:

(*Pause[3];*)NotebookWrite[InputNotebook[],
TemplateBox[{Dynamic[x]}, "blah",
DisplayFunction :> (OpenerBox[#] &)]]


Uncomment the Pause[3] to try it. Run it and select something in another input cell.

The problem is, in this example, that the OpenerBoxdoesn't open/close, or not until you convert the cell to cell expression and back to normal doing nothing, or until you cut and paste the OpenerBox, or until you write something in the cell expression, etc... Point is, the cell expression is perfect but it doesn't work until you slap the FE a little bit...

What's going on? How can I use a TemplateBox that gets pasted programatically to control some dynamic variable?

-
This seems to be an undocumented function, where did you find it? Name looks related to InterpretTemplate which Andy used in his recent question which also seems to be undocumented. –  Sjoerd C. de Vries Mar 17 '12 at 23:05
It is used plenty, very useful. In the Core.nb stylesheet there's a full (sub)section with definitions. I had found it first in library.wolfram.com/infocenter/Conferences/8010/…. I don't know that InterpretTemplate, I'm taking a look, thanks –  Rojo Mar 17 '12 at 23:09
Wow, this is freaky. While developing an answer for another question (which I hope will be really interesting) just last night, I tried to do exactly the same thing and made the identical discovery! I haven't had a chance to dig into the problem yet, but I will soon. Favoriting your question...and I'll swing back around when I have an answer. –  John Fultz Mar 18 '12 at 1:57
@FredDanielKline That's not relevant to this discussion. Sorry, I've been super-busy...I still intend to figure out what's going on here at some point. –  John Fultz Jun 1 '12 at 8:38

Pause[3]; NotebookWrite[InputNotebook[],