diff --git a/docs/plugins/development/templates.md b/docs/plugins/development/templates.md new file mode 100644 index 000000000..70228c623 --- /dev/null +++ b/docs/plugins/development/templates.md @@ -0,0 +1,195 @@ +# Templates + +## Base Templates + +The following template blocks are available on all templates. + +| Name | Required | Description | +|--------------|----------|---------------------------------------------------------------------| +| `title` | Yes | Page title | +| `content` | Yes | Page content | +| `head` | - | Content to include in the HTML `
` element | +| `javascript` | - | Javascript content included at the end of the HTML `` element | + +!!! note + For more information on how template blocks work, consult the [Django documentation](https://docs.djangoproject.com/en/stable/ref/templates/builtins/#block). + +### layout.html + +Path: `base/layout.html` + +NetBox provides a base template to ensure a consistent user experience, which plugins can extend with their own content. This is a general-purpose template that can be used when none of the function-specific templates below are suitable. + +#### Blocks + +| Name | Required | Description | +|-----------|----------|----------------------------| +| `header` | - | Page header | +| `tabs` | - | Horizontal navigation tabs | +| `modals` | - | Bootstrap 5 modal elements | + +#### Example + +An example of a plugin template which extends `layout.html` is included below. + +```jinja2 +{% extends 'base/layout.html' %} + +{% block header %} +{{ some_plugin_context_var }}
+{% endblock content %} +``` + +The first line of the template instructs Django to extend the NetBox base template and inject our custom content within its `content` block. + +!!! note + Django renders templates with its own custom [template language](https://docs.djangoproject.com/en/stable/topics/templates/#the-django-template-language). This is very similar to Jinja2, however there are some important distinctions of which authors should be aware. Be sure to familiarize yourself with Django's template language before attempting to create new templates. + +## Generic View Templates + +### object.html + +Path: `generic/object.html` + +This template is used by the `ObjectView` generic view to display a single object. + +#### Blocks + +| Name | Required | Description | +|---------------------|----------|----------------------------------------------| +| `breadcrumbs` | - | Breadcrumb list items (HTML `