Code Monkey home page Code Monkey logo

grav-plugin-file-content's Introduction

Grav File Content Plugin

File Content is a simple Grav plugin that adds a Twig extension to allow you to include a file into your template.

Installation

Installing the File Content plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

GPM Installation (Preferred)

The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's Terminal (also called the command line). From the root of your Grav install type:

bin/gpm install file-content

This will install the YouTube plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/file-content.

Manual Installation

To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to file-content. You can find these files either on GitHub or via GetGrav.org.

You should now have all the plugin files under

/your/site/grav/user/plugins/file-content

Config Defaults

enabled: true
allow_in_page: true                     # Allow files in the current page (e.g. sample.txt)
allow_in_grav: true                     # Allow files relative to Grav root (e.g. /user/data/custom/sample.txt)
allow_in_filesystem: false              # Allow files anywhere on filesystem (e.g. /users/myuser/myfolder/sample.txt)
allowed_extensions: [txt, html]         # Array of allowed file types to allow

If you need to change any value, then the best process is to copy the file-content.yaml file into your users/config/plugins/ folder (create it if it doesn't exist), and then modify there. This will override the default settings.

Use with caution! This plugin could be dangerous if you let anyone have access to your templates or even page content. They could include any file on your filesystem into your page.

Usage

This plugin provides both a Twig filter and function. To use them simply use the following syntax:

{{ filecontent('sample.txt') }}

or

{{ 'sample.txt'|filecontent }}

or 

{{ filecontent('/user/data/custom/sample.txt') }}

grav-plugin-file-content's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

noopable

grav-plugin-file-content's Issues

Is this plugin obsolete ? any alternative or is it fixable

Presume this plugin may just have a simple glitch .. but attempted to use it and not been able to load .txt , let alone a .html
Could someone possibly have a quick glance.. and maybe retire it , if its not really acceptable to use it / better ways.

Thanks

possible to import file content into a markdown file?

Hi Devs,

As I understand, this plugin only allows importing file content into twigs?
Would it be possible somehow to import file content into markdown files under user/pages/?

Something like modular files, I suppose ...

My specific requirement is for the Learn2 theme for documentation. I have some rather long and frequently changing API definitions. It would be great keep the skeleton of the documentation intact and import the modified files when updated.

Thanks.

Suggestion to simplify the syntax

Hello,
As we assume that pages are located in the folder /user/pages/
we could simply the syntax by adding few lines in the filecontent() function in FileContentTwigExtension.php

so we could get

{{ filecontent('/myincludes/myfile.txt') }}

instead of
{{ filecontent('/user/pages/myincludes/myfile.txt'') }}

just a suggestion, and very easy to implement?

thanks
senso+++++

public function filecontent($path)
...
                if ($config['allow_in_grav'] && file_exists(GRAV_ROOT . $path)) 
                {
                    return file_get_contents(GRAV_ROOT . $path);
                } 
                elseif ($config['allow_in_filesystem'] && file_exists($path)) 
                {
                    return file_get_contents($path);
                }
                // added by senso
                elseif (file_exists(GRAV_ROOT.'/user/pages'. $path)) 
                {
                return file_get_contents(GRAV_ROOT.'/user/pages'. $path);
                }
                // end senso suggestion
      ```        

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.