Including File Browser Plugin on page

Hello,
I’m trying to use the file browser plugin on my page. The way the readme says to use the plugin is that each page has to be set to the file_browser_plugin.html.twig page template. I want to create 1 page with multiple different instances of the file browser. I have tried using {% include ‘plugins://file-browser/templates/file_browser_plugin.html.twig’ %}, but this results in a crash saying page not found. How can I have atleast 2 instances of the file browser on my page? I only can adjust the file browser page by editting the .html.twig in the plugin folder as well.

Sorry for bad english in advanced. Cheers.

@seanparko, The plugin is not intended to be use with multiple instances on a single page. It’s hardcoded to find only a single instance of each required HTML element.

Contact the author if you have a feature request.

By the way:

  • You shouldn’t include the mentioned template.
    That template extends `base.html.twig, hence including that template will duplicate the page’s entire structure.
  • Including a template is done differently:
    {% include 'file_browser_plugin.html.twig' %}

Okay, what about having individual pages with file browsers on them? How can I have multiple file_browser_plugin.html? Thanks for your help.

1 Like

@seanparko, From your questions I sense a lack of insight in the concepts of Grav, at least about the working of templates and how templates are assigned to page files.

I think you’ve misinterpretted what I meant. If I only have 1 instance of file_browser_plugin.html.twig, and I can’t include the file browser in any other template instance, that means I can only have 1 page configuration with the file browser on it. Is there some way I can have multiple instances of that file so I can have different page layouts that have the file browser. Thank you.

@seanparko, That’s how the plugin has been designed… Its template is designed to be a toplevel page template and not as a partial that can be included in any other template like default, blog, modular/module.

Unfortunately, I’m not the author and not a user of the plugin. So I have not much more to contribute…

You could:

  • Create your own multiple versions of file_browser_plugin_xyz.html.twig and design them to your own liking.
  • Refactor the template into a partial.
  • Contact the author if you have a feature request.

Update: Issue created by OP: Trouble using it as a partial #19

Adding info here in case other users want to use this plugin. It still works fine, I was testing it yesterday with Grav v1.7.49.5.

I added a reply to the issues post left by @seanparko on the plugin github, but provide adapted version here.

how to implement this plugin

  • Copy the file file_browser_plugin.html.twig to your templates folder.
  • Create a page called ‘file browser’ as normal in the admin section, with the md file calling the file_browser_plugin.html.twig as its template. In user/pages you should now see a folder for ‘file browser’ with an .md file called file_browser_plugin.md
  • Configure the plugin as you like in admin, and add the file source. Use user://files first, to make sure its working. Experiment with other routing depending on your server and needs.
  • Note the font awesome setup in the admin options. This will depend on your own font awesome setup.
  • Plugin CSS can be customised in the usual way. E.g. add display-line to the buttons CSS, it plays nicer in the interface layout :slight_smile:

I did not manage to get it working with a path outside of the grav filetree on localhost but will test in a remote instance.

NB
The code in the provided template tells you what is happening - the top part is the plugin functionality, the bottom part (from about line 80, when the block content starts) is the viewable page in the front end. This isn’t to be used as an include partial, it’s a full page template that calls the base partial (for the header area of your interface).