Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

 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?

share|improve this question
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…. I don't know that InterpretTemplate, I'm taking a look, thanks – Rojolalalalalalalalalalalalala 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[], 
 TemplateBox[{Dynamic}, "Print", 
 DisplayFunction :> OpenerBox[(# &)]]]

Had to make name a valid function name.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.