EzDev.org

grav

grav - Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS Grav - A Modern Flat-File CMS | Grav grav is an easy to use, yet powerful, opensource cms that requires no database


How to filter image list with twig in grav

I am inserting a list of sponsor images in a sidebar in grav and want to show only images starting with sponsor_.

At the moment, my code adds any image in the page folder.

base.html.twig:

<div class="sidebar-right-content">
<!-- insert R sidebar images here     -->

<div class="sponsor-image">
  <h3>Sponsors</h3>
    {% for image in page.media.images %}
      <br>{{ image.html }}
    {% endfor %}
</div>

I have tried restricting the images returned by using the expression below, but no images are returned:

{% for image in page.media.images if image matches '/^sponsor.*$/' %}

Is there a way to use a filter in this context?


Source: (StackOverflow)

Composer install for subfolders

Anybody knows how to composer install for all subfolders too? Does the composer support it? Now I need to execute this command in each subfolder or add all subfolder's vendor folder to git.

I found solution in Linux: https://www.bram.us/2014/02/16/installing-dependencies-in-all-subfolder-organised-projects/

But how to do the same in Windows?

Example.

I have a project in C:\grav with composer.json in it. But also I have plugins folder C:\grav\user\plugins with composer.json in some of subfolders:

enter image description here

I want to execute composer install in C:\grav to install all dependencies in each C:\grav\user\plugins\* too.


Source: (StackOverflow)

PHP (cli) version doesn't match XAMPP version I installed

Recently I installed XAMPP for doing local development on my Windows 7 machine. I honestly didn't think PHP was installed at all before hand. I installed the latest version of XAMPP and configured for php 5.6.24. I created some virtual hosts and everything seemed to work.

I was having an issue and I needed to confirm which version of PHP I was using so I opened up my command line and typed php -v. For some reason it is reporting I'm using PHP 5.4.25. The exact line is PHP 5.4.25 (cli) (built: Feb 5 2014 21:19:58)

I don't recall using this version (I had Visual Studio Community installed recently, is that related?). I don't understand either why my CLI is reporting one version, when XAMPP supposedly installed another version. Am I missing something? I need to run some gpm commands for the latest version of Grav CMS but when I do it says it required at least 5.5.9.


Source: (StackOverflow)

Grav, get pages by taxonomy - page.url not working

In Grav which uses twig as a templating engine, I have:

<ul>
    {% for page in taxonomy.findTaxonomy({'tag': 'shell'}) %}
        <li><a rel='nofollow' href="{{ page.url }}">{{ page.title }}</a></li>
    {% endfor %}

</ul>

to get all pages that have tag set to shell -

However, page.title renders fine, but page.url gives %7B%7B%20page.url%20%7D%7D?

If I put page.url in place where page.title is, so between <a></a> tags, everything works fine? Is this some kind of bug?

EDIT

Exactly the same as described here: https://github.com/erusev/parsedown/issues/266

FOUND SOLUTION

Luckily Grav has an option to process twig first then markdown.

By setting twig_first: true into page meta, I was able to solve the problem.

So the culprit is markdown processor.


Source: (StackOverflow)

Unique page identifiers in Grav CMS

I'm using the Grav CMS to create a modular web page; however, I'm having difficulty customizing the layout based on how the content is generated.

I've followed the documentation found Grav main site from which I've model my site after.

My folder structure is essentially:

pages
    01.home
         _section1
         _section2

In each section folder I have my .md file. And each section is considered a sub-page of 'home'.

I've created the template file, modular.html.twig, in which I have the following code:

{% extends 'partials/base.html.twig' %}

{% block content %}
{% for child in page.children() %}
    {{ child.content() }}
{% endfor %}
{% endblock %}

This code iterates through sub-pages to load the content onto the home page. In my template I'm simply printing the result of the content using {{ content }}

What I end up with is a page with vertically stacked content and repeating html, as such.

What I want to do is uniquely define each sub-page (section) so that I can manipulate the content differently in my html, as such.

I've thought about creating separate template files for each section, but much of my content is nested.

For instance I have something akin to:

<div class="row">
   <div class="section-1">
      <h1>{{ content }}</h1>  <!--Needs to be unique-->
   </div>
   <div class="section-2">
      <h1>{{ content }}</h1>  <!--Needs to be unique-->
   </div>
</div>

Is it possible to accomplish what I'm trying to do with this framework? If so, how might I go about it?

Thank you


Source: (StackOverflow)

GRAV CMS -- Featherlight.js won't work with Cardstack theme

So apparently Cardstack theme for Grav has a conflict with Featherlight.js lightbox plugin. With the default Antimatter theme the plugin works fine, but with Cardstack there seems to be no way to get it working.

I installed the plugin via GPM as usual, then copied the featherlight.yaml file from user/plugins/featherlight/featherlight.yaml into user/config/plugins/featherlight.yaml and set active: true.

I then provided the markdown with ![image](image.jpg?lightbox=1024,800&resize=200,200) but nothing happens when you click the image.

We're able to use UI kit's lightbox (Cardstack is built on UIkit) with HTML. For example:
<a rel='nofollow' href="/user/pages/02.cards/test/01.test/mountains.jpg" data-uk-lightbox title="Mountains"> works, but we need a solution using Markdown. This is because, we're building a site where users post an image with a Markdown file with their name and other information. Asking users to write a lengthy HTML-link would be too demanding and prone to spelling errors.

I already posted about this on the Grav forum and it got one reply telling to open a issue on the Cardstack theme's github, which I did, but I haven't gotten any replies and the guy who built the theme hasn't been active for almost a month.


Source: (StackOverflow)

Deploying Grav CMS to Azure

After deploying a Grav CMS (http://getgrav.org) based website to Azure via a Bitbucket repo, I get the message "You do not have permission to view this directory or page." when I try to browse the site. I haven't changed any configuration settings yet.


Source: (StackOverflow)

Twig: attribute from html element filter/function

I am using the grav flatfile cms, and i have a twig variable that outputs something like:

<img src="example.com/path/to/image.jpg">

Is there a twig filter that can give me just the URL for the image (the contents of the src attribute)? or is there some regex filter that could help me?


Source: (StackOverflow)

How to handle page relationships in Grav CMS?

I currently have a few projects pages and I’m looking to display a list of team members that are associated with each project (a member may be associated with multiple projects) but I’m not sure how I can create this. A taxonomy doesn’t provide enough information (ideally want to show an image with name and short bio) so I’m assuming I’ll need to create a /team-members/ page with member pages below it and pull this in somehow to each project.

How would I go about allowing team members to be added to projects through the admin panel?


Source: (StackOverflow)

Grav CMS possibilities

I just started fiddling with grav and reading their documentation, but I have some questions about what it allows you to do.

In each post, in my markdown file, can I set some yaml or twig variables that link e.g. folder with images, and in template I check if this variable was set and output the Images, and if not I do nothing?

In Wordpress it's quite easy, but I wanted to experiment with something a bit smaller, faster and nicer to write in.


Source: (StackOverflow)

Unable to make file executable inside vagrant ssh

I'm trying to get the Grav CMS working inside my vagrant box but having trouble with permissions.

I've sshed into the box using vagrant ssh and traverse inside /var/www/public When I try running bin/gpm install admin I get a permission denied error.

So I go inside the bin folder and run ls -la and notice gpm and grav aren't executable:

drwxrwxrwx 1 vagrant vagrant     204 Nov 12 17:16 .
drwxrwxrwx 1 vagrant vagrant     748 Nov 12 15:40 ..
-rw-rw-rw- 1 vagrant vagrant 1705467 Nov  7 12:14 composer.phar
-rw-rw-rw- 1 vagrant vagrant    2171 Nov  7 12:14 gpm
-rw-rw-rw- 1 vagrant vagrant    1408 Nov  7 12:14 grav
-rw-rw-rw- 1 vagrant vagrant    4281 Nov  7 12:14 plugin

I've run sudo chmod +x gpm and nothing happens.

Am I doing something wrong??


Source: (StackOverflow)

Can you add multiple content blocks to Grav CMS templates

Just started using Grav CMS. I understand the concept of modular pages, but I really want to know if you can add multiple content blocks to a single page template. This way you could add two pieces of separate content to a single page from a single template.


Source: (StackOverflow)

How to disable username validation in Grav?

Grav version is 1.1.5

I removed every validation logic and validation pattern in source code, but it does not work, I still got error when I create a user.

The error message name is USERNAME_NOT_VALID, I search this in all source code and delete related code, but it still display on screen when I got error. I don't understand where the message from.

diff --git a/user/plugins/admin/pages/admin/register.md b/user/plugins/admin/pages/admin/register.md
index ff0b13b..fc0cf6e 100644
--- a/user/plugins/admin/pages/admin/register.md
+++ b/user/plugins/admin/pages/admin/register.md
@@ -9,7 +9,7 @@ form:
       validate:
         required: true
         message: PLUGIN_LOGIN.USERNAME_NOT_VALID
-        pattern: '^[a-z0-9_-]{3,16}$'
+        pattern: ''

     - name: email
       type: email
@@ -27,7 +27,7 @@ form:
       validate:
         required: true
         message: PLUGIN_ADMIN.PASSWORD_VALIDATION_MESSAGE
-        pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+        pattern: ''

     - name: password2
       type: password
@@ -36,7 +36,7 @@ form:
       validate:
         required: true
         message: PLUGIN_ADMIN.PASSWORD_VALIDATION_MESSAGE
-        pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+        pattern: ''

     - name: fullname
       type: text
diff --git a/user/plugins/login/pages/register.md b/user/plugins/login/pages/register.md
index c4088e2..0391367 100644
--- a/user/plugins/login/pages/register.md
+++ b/user/plugins/login/pages/register.md
@@ -12,7 +12,7 @@ form:
       validate:
         required: true
         message: PLUGIN_LOGIN.USERNAME_NOT_VALID
-        pattern: '^[a-z0-9_-]{3,16}$'
+        pattern: ''

     -
       name: email
@@ -31,7 +31,7 @@ form:
       validate:
         required: true
         message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
-        pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+        pattern: ''

     -
       name: password2
@@ -41,7 +41,7 @@ form:
       validate:
         required: true
         message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
-        pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+        pattern: ''

   buttons:
       -
diff --git a/user/plugins/login/pages/reset.md b/user/plugins/login/pages/reset.md
index e5f82e4..8300d2a 100644
--- a/user/plugins/login/pages/reset.md
+++ b/user/plugins/login/pages/reset.md
@@ -20,7 +20,7 @@ form:
           validate:
             required: true
             message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
-            pattern: '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}'
+            pattern: ''

         - name: token
           type: hidden



diff --git a/user/plugins/login/cli/ChangePasswordCommand.php b/user/plugins/login/cli/ChangePasswordCommand.php
index d15abb7..5bde6cc 100644
--- a/user/plugins/login/cli/ChangePasswordCommand.php
+++ b/user/plugins/login/cli/ChangePasswordCommand.php
@@ -134,9 +134,6 @@ class ChangePasswordCommand extends ConsoleCommand
     {
         switch ($type) {
             case 'user':
-                if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) {
-                    throw new \RuntimeException('Username should be between 3 and 16 characters, including lowercase letters, numbers, underscores, and hyphens. Uppercase letters, spaces, and special characters are not allowed');
-                }
                 if (!file_exists(self::getGrav()['locator']->findResource('account://' . $value . YAML_EXT))) {
                     throw new \RuntimeException('Username "' . $value . '" does not exist, please pick another username');
                 }
@@ -144,10 +141,6 @@ class ChangePasswordCommand extends ConsoleCommand
                 break;

             case 'password1':
-                if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) {
-                    throw new \RuntimeException('Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters');
-                }
-
                 break;

             case 'password2':
diff --git a/user/plugins/login/cli/ChangeUserStateCommand.php b/user/plugins/login/cli/ChangeUserStateCommand.php
index 40f9dc6..90adee6 100644
--- a/user/plugins/login/cli/ChangeUserStateCommand.php
+++ b/user/plugins/login/cli/ChangeUserStateCommand.php
@@ -133,9 +133,6 @@ class ChangeUserStateCommand extends ConsoleCommand
     {
         switch ($type) {
             case 'user':
-                if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) {
-                    throw new \RuntimeException('Username should be between 3 and 16 characters, including lowercase letters, numbers, underscores, and hyphens. Uppercase letters, spaces, and special characters are not allowed');
-                }
                 if (!file_exists(self::getGrav()['locator']->findResource('account://' . $value . YAML_EXT))) {
                     throw new \RuntimeException('Username "' . $value . '" does not exist, please pick another username');
                 }
diff --git a/user/plugins/login/cli/NewUserCommand.php b/user/plugins/login/cli/NewUserCommand.php
index 17dbf48..728adda 100644
--- a/user/plugins/login/cli/NewUserCommand.php
+++ b/user/plugins/login/cli/NewUserCommand.php
@@ -237,9 +237,6 @@ class NewUserCommand extends ConsoleCommand
     {
         switch ($type) {
             case 'user':
-                if (!preg_match('/^[a-z0-9_-]{3,16}$/', $value)) {
-                    throw new \RuntimeException('Username should be between 3 and 16 characters, including lowercase letters, numbers, underscores, and hyphens. Uppercase letters, spaces, and special characters are not allowed');
-                }
                 if (file_exists(Grav::instance()['locator']->findResource('account://' . $value . YAML_EXT))) {
                     throw new \RuntimeException('Username "' . $value . '" already exists, please pick another username');
                 }
@@ -247,10 +244,6 @@ class NewUserCommand extends ConsoleCommand
                 break;

             case 'password1':
-                if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) {
-                    throw new \RuntimeException('Password must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters');
-                }
-
                 break;

             case 'password2':

Source: (StackOverflow)

Deploying Grav CMS to Heroku

I'm using the RTFM Skeleton of Grav CMS and am trying to deploy it to Heroku, via GitHub. Heroku completes deployment, says that no errors occurred, but Heroku is just giving me 500 errors.

Does anyone know how to get this working? I was pointed toward the .htaccess file, but can't see anything obviously wrong (pasted below). Many thanks in advance.

<IfModule mod_rewrite.c>

RewriteEngine On

## Begin RewriteBase
# If you are getting 404 errors on subpages, you may have to uncomment the RewriteBase entry
# You should change the '/' to your appropriate subfolder. For example if you have
# your Grav install at the root of your site '/' should work, else it might be something
# along the lines of: RewriteBase /<your_sub_folder>
##

# RewriteBase /

## End - RewriteBase

## Begin - Exploits
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Grav
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Exploits

## Begin - Index
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
## End - Index

## Begin - Security
# Block all direct access for these folders
RewriteRule ^(.git|cache|bin|logs|backup)/(.*) error [L]
# Block access to specific file types for these folders
RewriteRule ^(system|user|vendor)/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$ error [L]
# Block all direct access to .md files:
RewriteRule \.md$ error [L]
# Block all direct access to files and folders beginning with a dot
RewriteRule (^\.|/\.) - [F]
# Block access to specific files in the root folder
RewriteRule ^(LICENSE|composer.lock|composer.json|nginx.conf|web.config)$ error [F]
## End - Security

</IfModule>

# Begin - Prevent Browsing and Set Default Resources
Options -Indexes
DirectoryIndex index.php index.html index.htm
# End - Prevent Browsing and Set Default Resources

Source: (StackOverflow)

Dockerfile for GRAV CMS

I am using Grav for blog and CMS, it is really a good markdown/flat CMS system.

In the documents site of Grav, most of the deployment guide are targeting to hosted VPC or cloud VMs, however, I am thinking about a better way and would like to seek help here:

  1. Edit the markdown file and git commit/push the content to github
  2. Use docker to do the continuous delivery
  3. To be specific, put a dockerfile under the root folder of Grav, config [docker public cloud] to automatically build Grav container image and push it to AWS when new commit happens on Github.

I am not good on PHP (Grav use PHP), so It is hard for me to write a good dockerfile for Grav. Could anyone give some hint or share a dockerfile for Grav? I am currently using this one but it is extremely slow on docker image build and always failed the build.

Many thanks for your help and input!


Source: (StackOverflow)