Import notebook
You can treat notebooks as sort of modules with its own isolated context. It might come handy, if you don't want to create a library, but still like to reuse some functions or templates from the other notebook.
Using the default importer with NotebookEvaluate or NotebookEvaluateAsync
nb = Import[path_String, "WLN"];
result = NotebookEvaluate[nb];
What it does?
- Evaluate all initialization cells in the isolated context (can be any kind of cell)
- Evaluate the last input cell in the notebook and return the result (must be wolfram language cell)
Since it involves breaking the order of evaluation, the given cel will be evaluated twice. We do recommend to use async version instead:
nb = Import[path_String, "WLN"];
Then[NotebookEvaluateAsync[nb], Function[result,
(* do something with the result *)
]];
Example
Let's make a notebook with WLX template, that you would like to reuse in other presentation notebooks
- Create a regular notebook with any structure you like
- Create a cell with our template (no need in evaluation)
.wlx
MakeTitle[Title__String] := MakeTitle[StringJoin[Title]]
MakeTitle[Title_String] := With[{
logo = "https://www.trr360.de/wp-content/uploads/2022/04/cropped-logo_small-1.png"
},
<div class="relative flex w-full text-left flex-row gap-x-4" style="align-items: center; margin-bottom:1.5rem;">
<div style="bottom:0; z-index:1; position: absolute; background: linear-gradient(to left, red, blue, green); width: 100%; height: 0.7rem;"></div>
<img style="margin:0; z-index:2; padding:0rem;" width="120" src="{logo}"/>
<h2><Title/></h2>
</div>
]
- Make it
initialization cell - Create a last single input cell
MakeTitle
This will basically "return" generated symbol from our notebook.
- Save you notebook as
template.wln
Now, it's time to test it!
- In your new notebook import the defined template
nb = Import["template.wln", "WLN"];
Then[NotebookEvaluateAsync[nb], Function[result,
BigTitle = result;
]];
- Use it in the desired context
.slide
<!-- .slide: class="text-left h-full" style="height:100%" -->
<BigTitle>$Fe_x Zn_{2-x} Mo_3 O_8$ is a platform for</BigTitle>
Content goes...
Content goes...
Content goes...

It does not have to be WLX template, it can be anything: regular Wolfram Expressions, dynamic content, module, a library and etc.
Benefits
- You can place tests, documentation in the same single file
- Fully lexically isolated
- Easier to deal with compared to Wolfram Packages
- Technically supports mixed content (Javascript code, HTML, WL)