Currently using PHP include in my site, any alternative in GRAV?

Hi, I’m currently using include($_SERVER["DOCUMENT_ROOT"] . "/assets/table.html"); in my site, and I’m trying to move to grav. I know there’s an injection plugin but somehow it only allows content under /user/pages and in markdown format.

I’ll put some of this assets under the grav /asset pages because this is not content to be shown individually (a comparison table that I modify sometimes), but to be called into different articles and inserted manually.

Is there any way to work around this? I really need this.

@iagovar, I see two possible avenues:

Using plugin 'Page Inject’

  • Copy ‘/user/plugins/page-inject/page-inject.yaml’ into folder ‘/user/config/plugins/’
  • In the copied config file, set property processed_content: false.
    This will tell the plugin to inject the raw table html into the page.
  • Copy your ‘table.html’ file into folder ‘/user/pages/includes/table/’ and rename it ‘table.md’.
  • Insert the following snippet into the content of the page in which you want to include ‘table.md’:
    [plugin:content-inject](/includes/table)
    
  • The HTML content from ‘table.md’ will now be injected into the page ‘as-is’

Using Twig templates:

  • Create an inherited theme.
  • In your inherited theme, create folder ‘/templates/includes’.
  • Copy your ‘table.html’ into that folder.
  • In the page in which you want to include ‘table.html’ add the following to the header:
    process:
        twig: true
    
  • In the same page, insert somewhere in the content:
    {% include 'includes/table.html' %}
    
  • The HTML content from ‘table.html’ will now be injected into the page ‘as-is’

Be advised that in both avenues, once the table has been inserted into the page, the page will not refresh its contents when you change the table. It has been cached. You will need to invalidate the cache to refresh the contents.

Thank you, I’ll try both although the Twig one seems less mantaining effort.

Also, is there any way to purge cache or disable cache for specific pages?

@iagovar,

Prevent caching of page:

  • Add the following to frontmatter of page:
    cache_enable: false
    

Invalidating the cache:

  • Save page with included html
    This will invalidate single page.
  • $ touch /user/pages/01.home/default.md
    This will invalidate single page.
  • $ touch /user/config/system.yaml
  • $ bin/grav cache
  • Delete files in ‘/cache’ folder