You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: pages/01.basics/03.installation/docs.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -97,7 +97,7 @@ If any issues are discovered during the initial page load (or after a cache-flus
97
97
98
98
Please consult the [Troubleshooting](../../troubleshooting) section for help regarding specific issues.
99
99
100
-
! If you have issues with file permissions, please check the [Permissions Troubleshooting documentation](/troubleshooting/permissions). Also you could look at the [Hosting Guides documentation](/hosting) that have specific instructions for various hosting environments
100
+
! If you have issues with file permissions, please check the [Permissions Troubleshooting documentation](/troubleshooting/permissions). Also you could look at the [Hosting Guides documentation](/webservers-hosting) that have specific instructions for various hosting environments
Copy file name to clipboardexpand all lines: pages/01.basics/05.grav-configuration/docs.md
+23-5
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ pages:
56
56
twig_first:false# Process Twig before markdown when processing both on a page
57
57
events:
58
58
page:true# Enable page level events
59
-
twig:true# Enable twig level events
59
+
twig:true# Enable Twig level events
60
60
markdown:
61
61
extra:false# Enable support for Markdown Extra support (GFM by default)
62
62
auto_line_breaks:false# Enable automatic line breaks
@@ -92,7 +92,7 @@ cache:
92
92
gzip:false# GZip compress the page output
93
93
94
94
twig:
95
-
cache:true# Set to true to enable twig caching
95
+
cache:true# Set to true to enable Twig caching
96
96
debug:true# Enable Twig debug
97
97
auto_reload:true# Refresh cache on changes
98
98
autoescape:false# Autoescape Twig vars
@@ -214,11 +214,29 @@ User configuration is completely optional. You can override as little or as much
214
214
215
215
You are also not limited to the `user/config/system.yaml` or the `user/config/site.yaml` files as described above. You can create any arbitrary `.yaml` configuration file in the `user/config` folder you wish and it will get picked up by Grav automatically.
216
216
217
-
Paths to the configuration files will be used as a **namespace** for your configuration options.
217
+
As an example if the new configuration file is named `user/config/data.yaml` and a yaml variable in this file is called count:
218
+
219
+
```
220
+
count: 39
221
+
```
222
+
223
+
The variable would be accessed in your Twig template by using the following syntax:
224
+
225
+
```
226
+
{{ config.data.count }}
227
+
```
228
+
229
+
It would also be accessible via PHP from any plugin with the code:
218
230
219
-
As an example if the new configuration file is named data.yaml and a yaml variable in this file is called count, the variable would be accessed in your twig template by using the following syntax:
! You can also provide a custom blueprint to enable your custom file to be editable in the admin plugin. Check out the relevant [recipe in the Admin Cookbook section](/cookbook/admin-recipes#add-a-custom-yaml-file).
236
+
237
+
## Config Variable Namespacing
238
+
239
+
Paths to the configuration files will be used as a **namespace** for your configuration options.
222
240
223
241
Alternatively, you can put all the options into one file and use YAML structures to specify the hierarchy for your configuration options. This namespacing is built from a combination of the **path + filename + option name**.
Copy file name to clipboardexpand all lines: pages/02.content/02.headers/docs.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -217,7 +217,7 @@ There are situations when you want to use Twig templating functionality in your
217
217
twig_first:false
218
218
```
219
219
220
-
If set to `true` Twig processing will occur before any Markdown processing. This can be particularly useful if your twig generates markdown that needs to be available in order to be processed by the Markdown compiler. One thing to note, if have `cache_enable: false`**and**`twig_first: true` page caching is effectively disabled.
220
+
If set to `true` Twig processing will occur before any Markdown processing. This can be particularly useful if your Twig generates markdown that needs to be available in order to be processed by the Markdown compiler. One thing to note, if have `cache_enable: false`**and**`twig_first: true` page caching is effectively disabled.
! This document outlines the use of `@page`, `@taxonomy.category` etc, but a more YAML-safe alternative format is `page@`, `[email protected]`. All the `@` commands can be written in either prefix or postfix format.
67
70
@@ -143,32 +146,32 @@ content:
143
146
144
147
## Page Collections
145
148
146
-
##### @page - Collection of children of a specific page
149
+
##### @pageor @page.children - Collection of children of a specific page
147
150
148
151
This collection takes a slug route of a page as an argument and will return all the **published non-modular** children of that page
149
152
150
153
```ruby
151
154
content:
152
155
items:
153
-
'@page': /blog
156
+
'@page': '/blog'
154
157
```
155
158
156
159
alternatively:
157
160
158
161
```ruby
159
162
content:
160
163
items:
161
-
'@page.children': /blog
164
+
'@page.children': '/blog'
162
165
```
163
166
164
-
##### @page.self - Collection of just the specific page
167
+
##### @page.self or @page.page - Collection of just the specific page
165
168
166
169
This collection takes a slug route of a page as an argument and will return collection containing that page (if it is **published and non-modular**)
167
170
168
171
```ruby
169
172
content:
170
173
items:
171
-
'@page.self': /blog
174
+
'@page.self': '/blog'
172
175
```
173
176
174
177
##### @page.descendants - Collection of children + all descendants of a specific page
@@ -178,9 +181,20 @@ This collection takes a slug route of a page as an argument and will return all
178
181
```ruby
179
182
content:
180
183
items:
181
-
'@page.descendants': /blog
184
+
'@page.descendants': '/blog'
182
185
```
183
186
187
+
##### @page.modular - Collection of modular children of a specific page
188
+
189
+
This collection takes a slug route of a page as an argument and will return all the **published modular** children of that page
Copy file name to clipboardexpand all lines: pages/02.content/11.multi-language/docs.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -192,7 +192,7 @@ This way Grav knows how to route your to the homepage if the active language is
192
192
193
193
#### Language-Based Twig Templates
194
194
195
-
By default, Grav uses the markdown filename to determine the Twig template to use to render. This works with multi-language the same way. For example, `default.fr.md` would look for a twig file called `default.html.twig` in the appropriate Twig template paths of the current theme and any plugins that register Twig template paths. With multi-language, Grav also adds the current active language to the path structure. What this means is that if you need to have a language-specific Twig file, you can just put those into a root level language folder. For example if your current theme is using a template located at `templates/default.html.twig` you can create an `templates/fr/` folder, and put your French-specific Twig file in there: `templates/fr/default.html.twig`.
195
+
By default, Grav uses the markdown filename to determine the Twig template to use to render. This works with multi-language the same way. For example, `default.fr.md` would look for a Twig file called `default.html.twig` in the appropriate Twig template paths of the current theme and any plugins that register Twig template paths. With multi-language, Grav also adds the current active language to the path structure. What this means is that if you need to have a language-specific Twig file, you can just put those into a root level language folder. For example if your current theme is using a template located at `templates/default.html.twig` you can create an `templates/fr/` folder, and put your French-specific Twig file in there: `templates/fr/default.html.twig`.
196
196
197
197
Another option which requires manual setup is to override the `template:` setting in the page headers. For example:
As is typical with most web platforms, Grav's default content type is **HTML**. This means than when a user requests a route in their browser, for example: `/blog/new-macbook-pros-soon`, because there is no file extension Grav assumes you are requesting an HTML page. If your page was defined by a page with filename of `blog-item.md`, Grav in turn looks for a Twig template called `blog-item.html.twig` to render the page.
10
+
11
+
If the user requested the type explicitly via `/blog/new-macbook-pros-soon.html`, Grav would still look for that same `blog-item.html.twig` file.
12
+
13
+
## Other Content Types
14
+
15
+
Grav is a flexible platform however, and can actually serve up any content type you could wish for (`xml`, `rss`, `json`, `pdf`, etc.), you just have to provide a way to render it appropriately.
16
+
17
+
If you were to request a route with a `.xml` extension, for example: `/blog.xml`, instead of using the regular `blog.html.twig` template to render it,
18
+
Grav look for a template called `blog.xml.twig`. You would need to ensure that template output the appropriate XML structure.
19
+
20
+
### Example with JSON files
21
+
22
+
A particular common way to access files is via a `.json` extension. This is allows data to be requested via JSON files that are easily processed by JavaScript.
23
+
24
+
Say you wanted the **frontmatter** and **content** of a particular page in JSON format, and that page was defined in a file called `item.md`. All you would need to do is to provide a Twig template called `item.json.html`. You could put this in your theme's `templates/` folder, or if you were using a plugin to load custom templates, you could add it there.
25
+
26
+
The contents of this `item.json.twig` file could look something like:
27
+
28
+
```
29
+
{% set payload = {frontmatter: page.header, content: page.content} %}
30
+
{{ payload|json_encode|raw }}
31
+
```
32
+
33
+
All this Twig file does is create an array with the page header as **frontmatter** and page **content**, then uses the Twig `json_encode` filter to encode it.
34
+
35
+
When a user requests the url: `/blog/new-macbook-pros-soon.json` this new Twig file would be used and the output sent would be in the format:
36
+
37
+
```
38
+
{
39
+
"header":{
40
+
"title":"New Macbook Pros Arriving Soon",
41
+
"date": "14:23 08/01/2016",
42
+
"taxonomy":{
43
+
"category":[
44
+
"blog"
45
+
],
46
+
"tag":[
47
+
"apple",
48
+
"mbpr",
49
+
"laptops"
50
+
]
51
+
}
52
+
},
53
+
"content":"<p>this has an -> arrow here and <strong>bold</strong> here</p>\n<blockquote>\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies tristique nulla et mattis. Phasellus id massa eget nisl congue blandit sit amet id ligula. Praesent et nulla eu augue tempus sagittis. Mauris faucibus nibh et nibh cursus in vestibulum sapien egestas. Curabitur ut lectus tortor. Sed ipsum eros, egestas ut eleifend non, elementum vitae eros.\n-- <cite> Ronald Wade</cite></p>\n</blockquote>\n<p>Mauris felis diam, pellentesque vel lacinia ac, dictum a nunc. Mauris mattis nunc sed mi sagittis et facilisis tortor volutpat. Etiam tincidunt urna mattis erat placerat placerat ac eu tellus.</p>\n<p>This is a new paragraph</p>\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies tristique nulla et mattis.</p>"
54
+
}
55
+
```
56
+
57
+
This is valid JSON that can easily be parsed and processed by JavaScript. Easy Peasy!
58
+
59
+
## Custom Content Types
60
+
61
+
In order to send the data with the appropriate content type, Grav needs to know the MIME type that the browser expects in order for it to render that content type. Grav knows about most of the standard content types as defined in the `system/config/media.yaml` file. If you wish to handle a content type that is not provided, you just need to add an entry to this file.
62
+
63
+
For example, if you wish to be able to render iCal calendar events, you would need to add this media type to the `media.yaml`:
64
+
65
+
```
66
+
ics:
67
+
type: iCal
68
+
thumb: media/thumb.png
69
+
mime: text/calendar
70
+
```
71
+
72
+
This defines the `.ics` file extension as an `iCal` file with mime type: `text/calendar`. Then all you need to do is provide the appropriate `.ical.twig` template to render any file you request of this type.
Copy file name to clipboardexpand all lines: pages/03.themes/01.theme-basics/docs.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,15 @@ Themes in Grav are quite simple, and very flexible because they are built with t
8
8
9
9
## Content Pages & Twig Templates
10
10
11
-
The first thing to understand is the direct relationship between **pages** in Grav and the **twig template files** that are provided in a theme.
11
+
The first thing to understand is the direct relationship between **pages** in Grav and the **Twig template files** that are provided in a theme.
12
12
13
13
Each page you create references a specific template file, either by the name of the page file, or by setting the template header variable for the page. For simpler maintenance, we advise using the page name rather than overriding it with the header variable, whenever possible.
14
14
15
-
Let us work through a simple example. If you have [installed the **Grav Base** package](../../basics/installation) you will notice that in the `user/pages/01.home` folder, you have a file called `default.md` which contains the markdown-based content for the page. The name of this file, i.e. `default` tells Grav that this page should be rendered with the twig template called `default.html.twig` which is located in the theme's `templates/` folder.
15
+
Let us work through a simple example. If you have [installed the **Grav Base** package](../../basics/installation) you will notice that in the `user/pages/01.home` folder, you have a file called `default.md` which contains the markdown-based content for the page. The name of this file, i.e. `default` tells Grav that this page should be rendered with the Twig template called `default.html.twig` which is located in the theme's `templates/` folder.
16
16
17
17
!! Page templates must be lowercase, like "default", "blog", etc.
18
18
19
-
If you were to have a page file called `blog.md`, Grav would try to render it with the twig template: `<your_theme>/templates/blog.html.twig`.
19
+
If you were to have a page file called `blog.md`, Grav would try to render it with the Twig template: `<your_theme>/templates/blog.html.twig`.
20
20
21
21
!! The names of files in Grav do not appear on the frontend of Grav. Only the folder names do. Don't worry if all of your blog posts have the same file name. This is normal.
22
22
@@ -114,13 +114,13 @@ You can then use the provided **plugins methods** which are covered in the [next
114
114
115
115
### Templates
116
116
117
-
There are **no set rules** regarding the structure of a Grav theme except that there must be appropriate twig templates provided in the `templates/` folder for each of the page types you use in your content.
117
+
There are **no set rules** regarding the structure of a Grav theme except that there must be appropriate Twig templates provided in the `templates/` folder for each of the page types you use in your content.
118
118
119
-
!! Because of this tight coupling between page content and twig templates in a theme, it often makes sense to develop themes in conjunction with the content they are intended to be used with. A good way to create _general_ themes is to support the template types used by the Skeleton packages that are available on our [downloads page](http://getgrav.org/downloads). For example, support: **default**, **blog**, **error**, **item**, and **modular**.
119
+
!! Because of this tight coupling between page content and Twig templates in a theme, it often makes sense to develop themes in conjunction with the content they are intended to be used with. A good way to create _general_ themes is to support the template types used by the Skeleton packages that are available on our [downloads page](http://getgrav.org/downloads). For example, support: **default**, **blog**, **error**, **item**, and **modular**.
120
120
121
121
Generally speaking, the root of the `templates/` folder should be used to house the primary templates that are supported, then create a sub-folder called `partials/` to contain parts, or smaller template _chunks_.
122
122
123
-
If you want to support **modular** templates in your theme, you should also create a sub-folder of templates called `modular/` and store your modular twig template files in there.
123
+
If you want to support **modular** templates in your theme, you should also create a sub-folder of templates called `modular/` and store your modular Twig template files in there.
124
124
125
125
The story for supporting **forms** is the same. Create another sub-folder called `forms/` and store any custom form templates in it.
0 commit comments