|
@@ -5,7 +5,7 @@
|
|
|
NetBox uses [Jinja](https://jinja.palletsprojects.com/) to render [configuration templates](../../features/configuration-rendering.md). Plugins can extend this rendering pipeline in two complementary ways:
|
|
NetBox uses [Jinja](https://jinja.palletsprojects.com/) to render [configuration templates](../../features/configuration-rendering.md). Plugins can extend this rendering pipeline in two complementary ways:
|
|
|
|
|
|
|
|
1. **Register custom filters** — make new template filters available by name in every config template.
|
|
1. **Register custom filters** — make new template filters available by name in every config template.
|
|
|
-2. **Inject context variables** — add extra variables that are available inside every config template render.
|
|
|
|
|
|
|
+2. **Inject context variables** — add extra variables that are available inside every config template and export template render.
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
@@ -83,7 +83,7 @@ JINJA_FILTERS = {
|
|
|
|
|
|
|
|
## Injecting Context Variables
|
|
## Injecting Context Variables
|
|
|
|
|
|
|
|
-Override `get_jinja_context()` in your `PluginConfig` subclass to inject additional variables into every config template render context.
|
|
|
|
|
|
|
+Override `get_jinja_context()` in your `PluginConfig` subclass to inject additional variables into every config template and export template render context.
|
|
|
|
|
|
|
|
```python title="my_plugin/__init__.py"
|
|
```python title="my_plugin/__init__.py"
|
|
|
from netbox.plugins import PluginConfig
|
|
from netbox.plugins import PluginConfig
|
|
@@ -99,14 +99,14 @@ class MyPluginConfig(PluginConfig):
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-The returned dict is merged into the template context, so `my_plugin` becomes available by name inside every config template:
|
|
|
|
|
|
|
+The returned dict is merged into the template context, so `my_plugin` becomes available by name inside every config template and export template:
|
|
|
|
|
|
|
|
```jinja2
|
|
```jinja2
|
|
|
{% set records = my_plugin.lookup(device.name) %}
|
|
{% set records = my_plugin.lookup(device.name) %}
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
!!! warning "Startup cost"
|
|
!!! warning "Startup cost"
|
|
|
- `get_jinja_context()` is called on **every** config template render, not once at startup. Keep it fast. Defer expensive lookups to the object you return rather than performing them in `get_jinja_context()` itself.
|
|
|
|
|
|
|
+ `get_jinja_context()` is called on **every** config template and export template render, not once at startup. Keep it fast. Defer expensive lookups to the object you return rather than performing them in `get_jinja_context()` itself.
|
|
|
|
|
|
|
|
!!! note "Conflict avoidance"
|
|
!!! note "Conflict avoidance"
|
|
|
Choose context variable names that are unlikely to collide with NetBox's built-in template variables (`device`, `queryset`, etc.) or with those contributed by other plugins. Prefixing with your plugin name is strongly recommended.
|
|
Choose context variable names that are unlikely to collide with NetBox's built-in template variables (`device`, `queryset`, etc.) or with those contributed by other plugins. Prefixing with your plugin name is strongly recommended.
|