[IPython-dev] Template cells

Matthias BUSSONNIER bussonniermatthias at gmail.com
Sat Dec 15 15:03:23 EST 2012


Le 15 déc. 2012 à 20:07, Thomas Kluyver a écrit :

> Revisiting a discussion from a few days ago, to get more input.
> 
> At one point, we were considering ways to interpolate variables from the Python namespace into Markdown cells, using custom syntax and transferring simple variables using the user_expressions field of execution messages.
> 
> Prompted by another discussion, I felt that this approach was quite limiting, and a better approach would be to have a 'template cell', designed like this:
> 
I like the idea of template, I'm still wondering if it is not going too far.

> - To the user, it works like a Markdown cell; when they leave the cell, the editor is replaced by the rendered version of the contents.
> - Since we now depend on Jinja2 for the notebook, we use the template syntax from that, rather than reinventing a restricted template syntax ourselves. This gives us things like loops in the templates.

Jinja is python only, am I wrong ? And feel this would be a little too restrictive, moreover it will mix what the kernel does and what the server does. 
I'm not a big fan of having the server computing repr for the frontend... (even if we will have to go through this for multiuser) 

> - To render the cell, it is sent to the kernel as an execution request.
You stat to imply that the kernel does know it speaks to notebook...

> - The rendering uses our display infrastructure, so e.g. the HTML representation of an object is preferred. But the template can override this to get the plain text repr.
> 
> Open questions:
> - Should the templates be in Markdown (for consistency with other rich-text cells), or in HTML (which is more common in templating)?
> - If in Markdown, should they be an automatic feature of Markdown cells (i.e. the Javascript looks for template syntax, and decides to send it to the kernel)? Or is that too surprising?
> - How can we ensure notebooks with template cells work with current versions of IPython, which don't know about them?
This one is tough.

> - Should there be any way to tell template cells to automatically re-render, e.g. on a timer, or after another cell is executed?
It would lead to confusion unless the cell is explicitly and visually marked as being a live representation of the kernel. 

Why not a Jinja2 object in python that could return what you wish ? 

If you can show user_expression/variable in mdcell, you just have to reference this Jinja object... it has the same effect no ? 
And you could change the template engine if the kernel is not Python...

-- 
Matthias




More information about the IPython-dev mailing list