NotebookEvaluateAsModule
Wolfram Kernel
NotebookEvaluateAsModule[path_String | f_File]
NotebookEvaluateAsModule[notebook_RemoteNotebook]imports WLJS notebook as an isolated module/library:
{exports} = NotebookEvaluateAsModule["mySecondNotebook.wln"];This breaks the evaluation order. The caller cell will be evaluated last in the queue. Consider using the safer async version NotebookEvaluateAsModuleAsync instead.
The following rules apply:
- Initialization cells are evaluated once for a given notebook object
- The last Wolfram input cell is evaluated on every call and its result is exported
- All other cells are ignored
This allows you to create reusable components using plain notebooks. For example:
Notebook-1.wln
.wlx
BigHeader[Text_String] := <h1><Text/></h1>;{BigHeader}Then in the host notebook we can import the result of the previous notebook as a component:
Notebook-2.wln
{HeaderComponent} = NotebookEvaluateAsModule["Notebook-1.wln"];.slide
<HeaderComponent>Here is my presentation</HeaderComponent>
Hi there!