Module 7 · Lesson 211 min
Templates and loading
Once your layouts get repetitive, factor the repetition into templates. A pane_template names a reusable pane; a tab_template names a reusable tab. Define once, then use the name like a built-in node.
A pane template
pane_template name="htop" {
command "htop"
}
// then use it just by name:
// htopA tab template with a sidebar
tab_template name="ranger-on-the-side" {
pane size=1 borderless=true {
plugin location="zellij:compact-bar"
}
pane split_direction="vertical" {
pane command="ranger" size="20%"
children
}
}There are three ways to load a layout. Give a path, give a bare name to pull one from your layouts directory, or give a URL (which Zellij will ask you to approve first). Applying a layout inside a running session adds new tabs rather than replacing what’s there.
Loading layouts
zellij --layout /path/to/dev.kdl # by path
zellij --layout dev # by name, from ~/.config/zellij/layouts
zellij --layout https://example.com/dev.kdl # by URL (asks approval)Try it yourself
Do
Install a layout you can load by name
Put a layout where Zellij can find it by name.
- Create the layouts dir if needed:
mkdir -p ~/.config/zellij/layouts(macOS: under the Application Support path) - Copy your
dev.kdlthere - Start it with just its name:
zellij --layout dev
Done when
zellij --layout dev loaded your layout by name from the layouts directory. Recall
Recall the slot
Templates hinge on this.
In a tab_template, what does the children keyword do?
Reveal answer
It marks the slot where the panes listed at the use-site are inserted, so the template can wrap your content instead of replacing it.