diff --git a/docs/docs/extend/plugins/urls.md b/docs/docs/extend/plugins/urls.md index ed6b019442..f593c0bd30 100644 --- a/docs/docs/extend/plugins/urls.md +++ b/docs/docs/extend/plugins/urls.md @@ -25,20 +25,33 @@ The URLs get exposed under `/plugin/{plugin.slug}/*` and get exposed to the temp ### Views If your plugin will implement and host another webpage, familiarize yourself with Django views. Implementation is exactly the same. -A good place to start is the [django documentation](https://docs.djangoproject.com/en/4.2/topics/http/views/). +A good place to start is the [django documentation](https://docs.djangoproject.com/en/4.2/topics/http/views/). Additional InvenTree-specific information is below. ### Rendering Views -Rendering templated views is also supported. Templated HTML files should be placed inside a 'templates' subfolder in your plugin folder. -Placed here, the template can be called using the file name (ex: `render(request, 'test.html', context)`) +Rendering templated views is also supported. Templated HTML files should be placed inside your plugin folder in a sub folder called `templates`. +Placed here, the template can be called using the file name and the render command. -### Implementing a Page Base -Some plugins require a page with a navbar, sidebar, and content. -This can be done within a templated HTML file. Extend the file "page_base.html". This can be done by placing the following line at the top of the file. -``` HTML -{% raw %}{% extends "page_base.html" %}{% endraw %} +Example in context (inside the main plugin python file): +``` py +def view_test(self, request): + return render(request, 'test.html', context) + +def setup_urls(self): + return [ + re_path(r'^test/', self.view_test, name='test') + ] ``` -Additionally, you should add the following imports after the extended line. +### Implementing the Page Base +Some plugins require a page with a navbar, sidebar, and content similar to other InvenTree pages. +This can be done within a templated HTML file by extending the file "page_base.html". To do this, place the following line at the top of your template file. +``` HTML +{% raw %} +{% extends "page_base.html" %} +{% endraw %} +``` + +Additionally, add the following imports after the extended line. ``` HTML {% raw %} {% load static %} @@ -51,17 +64,57 @@ Additionally, you should add the following imports after the extended line. #### Blocks The page_base file is split into multiple sections called blocks. This allows you to implement sections of the webpage while getting many items like navbars, sidebars, and general layout provided for you. -The current page base can be found [here](https://github.com/inventree/InvenTree/blob/master/InvenTree/templates/page_base.html). This will provide you with what blocks you can override. The [stock app](https://github.com/inventree/InvenTree/tree/master/InvenTree/stock) offers a great example of implementing these blocks. +The current default page base can be found [here](https://github.com/inventree/InvenTree/blob/master/InvenTree/templates/page_base.html). Look through this file to determine overridable blocks. The [stock app](https://github.com/inventree/InvenTree/tree/master/InvenTree/stock) offers a great example of implementing these blocks. !!! warning "Sidebar Block" - You may notice that implementing the `sidebar` block does not work. The most likely issue is that you are not enabling the sidebar using JavaScript. To fix this, append the following code to the end of your template file. + You may notice that implementing the `sidebar` block doesn't initially work. Be sure to enable the sidebar using JavaScript. This can be achieved by appending the following code, replacing `label` with a label of your choosing, to the end of your template file. ``` HTML {% raw %} {% block js_ready %} {{ block.super }} - enableSidebar('stocklocation'); - - + enableSidebar('label'); {% endblock js_ready %} {% endraw %} ``` + +#### Panels +InvenTree uses bootstrap panels to display the page's content. These panels are locate inside the block `page_content`. + +Example: +```html +{% raw %} +