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?

  • $\begingroup$ 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. $\endgroup$ Mar 17, 2012 at 23:05
  • $\begingroup$ 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 $\endgroup$
    – Rojo
    Mar 17, 2012 at 23:09
  • 1
    $\begingroup$ 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. $\endgroup$
    – John Fultz
    Mar 18, 2012 at 1:57
  • $\begingroup$ @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. $\endgroup$
    – John Fultz
    Jun 1, 2012 at 8:38

1 Answer 1

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

Had to make name a valid function name.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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