Skip to content

Commit 03d475c

Browse files
committed
Update Pico's sample contents to reflect the changes of Pico 2.1
1 parent dec4481 commit 03d475c

File tree

2 files changed

+139
-88
lines changed

2 files changed

+139
-88
lines changed

content-sample/_meta.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
social:
2+
Social:
33
- title: Visit us on GitHub
44
url: https://github.com/picocms/Pico
55
icon: octocat

content-sample/index.md

Lines changed: 138 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ page instead.
8585
As a common practice, we recommend you to separate your contents and assets
8686
(like images, downloads, etc.). We even deny access to your `content` directory
8787
by default. If you want to use some assets (e.g. a image) in one of your content
88-
files, you should create an `assets` folder in Pico's root directory and upload
89-
your assets there. You can then access them in your Markdown using
90-
<code>&#37;base_url&#37;/assets/</code> for example:
91-
<code>!\[Image Title\](&#37;base_url&#37;/assets/image.png)</code>
88+
files, use Pico's `assets` folder. You can then access them in your Markdown
89+
using the <code>&#37;assets_url&#37;</code> placeholder, for example:
90+
<code>!\[Image Title\](&#37;assets_url&#37;/assets/image.png)</code>
9291

9392
### Text File Markup
9493

@@ -121,17 +120,23 @@ classes to your theme. For example, you might want to add some CSS classes to
121120
your theme to rule how much of the available space a image should use (e.g.
122121
`img.small { width: 80%; }`). You can then use these CSS classes in your
123122
Markdown files, for example:
124-
<code>!\[Image Title\](&#37;base_url&#37;/assets/image.png) {.small}</code>
123+
<code>!\[Image Title\](&#37;assets_url&#37;/image.png) {.small}</code>
125124

126125
There are also certain variables that you can use in your text files:
127126

128127
* <code>&#37;site_title&#37;</code> - The title of your Pico site
129128
* <code>&#37;base_url&#37;</code> - The URL to your Pico site; internal links
130129
can be specified using <code>&#37;base_url&#37;?sub/page</code>
131130
* <code>&#37;theme_url&#37;</code> - The URL to the currently used theme
131+
* <code>&#37;assets_url&#37;</code> - The URL to Pico's `assets` directory
132+
* <code>&#37;themes_url&#37;</code> - The URL to Pico's `themes` directory;
133+
don't confuse this with <code>&#37;theme_url&#37;</code>
134+
* <code>&#37;plugins_url&#37;</code> - The URL to Pico's `plugins` directory
132135
* <code>&#37;version&#37;</code> - Pico's current version string (e.g. `2.0.0`)
133136
* <code>&#37;meta.&#42;&#37;</code> - Access any meta variable of the current
134137
page, e.g. <code>&#37;meta.author&#37;</code> is replaced with `Joe Bloggs`
138+
* <code>&#37;config.&#42;&#37;</code> - Access any scalar config variable,
139+
e.g. <code>&#37;config.theme&#37;</code> is replaced with `default`
135140

136141
### Blogging
137142

@@ -154,14 +159,12 @@ something like the following:
154159
`index.twig`), it will create a list of all your blog articles. Add the
155160
following Twig snippet to `blog-index.twig` near `{{ content }}`:
156161
```
157-
{% for page in pages|sort_by("time")|reverse %}
158-
{% if page.id starts with "blog/" and not page.hidden %}
159-
<div class="post">
160-
<h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
161-
<p class="date">{{ page.date_formatted }}</p>
162-
<p class="excerpt">{{ page.description }}</p>
163-
</div>
164-
{% endif %}
162+
{% for page in pages("blog")|sort_by("time")|reverse if not page.hidden %}
163+
<div class="post">
164+
<h3><a href="{{ page.url }}">{{ page.title }}</a></h3>
165+
<p class="date">{{ page.date_formatted }}</p>
166+
<p class="excerpt">{{ page.description }}</p>
167+
</div>
165168
{% endfor %}
166169
```
167170

@@ -179,95 +182,153 @@ details.
179182

180183
### Themes
181184

182-
You can create themes for your Pico installation in the `themes` folder. Check
183-
out the default theme for an example. Pico uses [Twig][] for template
184-
rendering. You can select your theme by setting the `theme` option in
185-
`config/config.yml` to the name of your theme folder.
185+
You can create themes for your Pico installation in the `themes` folder. Pico
186+
uses [Twig][] for template rendering. You can select your theme by setting the
187+
`theme` option in `config/config.yml` to the name of your theme folder.
188+
189+
[Pico's default theme][PicoTheme] isn't really intended to be used for a
190+
productive website, it's rather a starting point for creating your own theme.
191+
If the default theme isn't sufficient for you, and you don't want to create
192+
your own theme, you can use one of the great themes third-party developers and
193+
designers created in the past. As with plugins, you can find themes in
194+
[our Wiki][WikiThemes] and on [our website][OfficialThemes].
186195

187196
All themes must include an `index.twig` file to define the HTML structure of
188-
the theme. Below are the Twig variables that are available to use in your
189-
theme. Please note that paths (e.g. `{{ base_dir }}`) and URLs
190-
(e.g. `{{ base_url }}`) don't have a trailing slash.
197+
the theme, and a `pico-theme.yml` to set the necessary config parameters. Just
198+
refer to Pico's default theme as an example. You can use different templates
199+
for different content files by specifying the `Template` meta header. Simply
200+
add e.g. `Template: blog` to the YAML header of a content file and Pico will
201+
use the `blog.twig` template in your theme folder to display the page.
202+
203+
Below are the Twig variables that are available to use in themes. Please note
204+
that URLs (e.g. `{{ base_url }}`) never include a trailing slash.
191205

192206
* `{{ site_title }}` - Shortcut to the site title (see `config/config.yml`)
193207
* `{{ config }}` - Contains the values you set in `config/config.yml`
194208
(e.g. `{{ config.theme }}` becomes `default`)
195-
* `{{ base_dir }}` - The path to your Pico root directory
196209
* `{{ base_url }}` - The URL to your Pico site; use Twig's `link` filter to
197210
specify internal links (e.g. `{{ "sub/page"|link }}`),
198211
this guarantees that your link works whether URL rewriting
199212
is enabled or not
200-
* `{{ theme_dir }}` - The path to the currently active theme
201213
* `{{ theme_url }}` - The URL to the currently active theme
202-
* `{{ version }}` - Pico's current version string (e.g. `2.0.0`)
214+
* `{{ assets_url }}` - The URL to Pico's `assets` directory
215+
* `{{ themes_url }}` - The URL to Pico's `themes` directory; don't confuse this
216+
with `{{ theme_url }}`
217+
* `{{ plugins_url }}` - The URL to Pico's `plugins` directory
218+
* `{{ version }}` - Pico's current version string (e.g. `%version%`)
203219
* `{{ meta }}` - Contains the meta values of the current page
204-
* `{{ meta.title }}`
205-
* `{{ meta.description }}`
206-
* `{{ meta.author }}`
207-
* `{{ meta.date }}`
208-
* `{{ meta.date_formatted }}`
209-
* `{{ meta.time }}`
210-
* `{{ meta.robots }}`
220+
* `{{ meta.title }}` - The `Title` YAML header
221+
* `{{ meta.description }}` - The `Description` YAML header
222+
* `{{ meta.author }}` - The `Author` YAML header
223+
* `{{ meta.date }}` - The `Date` YAML header
224+
* `{{ meta.date_formatted }}` - The formatted date of the page as specified
225+
by the `date_format` parameter in your
226+
`config/config.yml`
227+
* `{{ meta.time }}` - The [Unix timestamp][UnixTimestamp] derived from the
228+
`Date` YAML header
229+
* `{{ meta.robots }}` - The `Robots` YAML header
211230
* ...
212231
* `{{ content }}` - The content of the current page after it has been processed
213232
through Markdown
214-
* `{{ pages }}` - A collection of all the content pages in your site
215-
* `{{ page.id }}` - The relative path to the content file (unique ID)
216-
* `{{ page.url }}` - The URL to the page
217-
* `{{ page.title }}` - The title of the page (YAML header)
218-
* `{{ page.description }}` - The description of the page (YAML header)
219-
* `{{ page.author }}` - The author of the page (YAML header)
220-
* `{{ page.time }}` - The [Unix timestamp][UnixTimestamp] derived from
221-
the `Date` header
222-
* `{{ page.date }}` - The date of the page (YAML header)
223-
* `{{ page.date_formatted }}` - The formatted date of the page as specified
224-
by the `date_format` parameter in your
225-
`config/config.yml`
226-
* `{{ page.raw_content }}` - The raw, not yet parsed contents of the page;
227-
use Twig's `content` filter to get the parsed
228-
contents of a page by passing its unique ID
229-
(e.g. `{{ "sub/page"|content }}`)
230-
* `{{ page.meta }}`- The meta values of the page (see `{{ meta }}` above)
231-
* `{{ page.previous_page }}` - The data of the respective previous page
232-
* `{{ page.next_page }}` - The data of the respective next page
233-
* `{{ page.tree_node }}` - The page's node in Pico's page tree
234-
* `{{ prev_page }}` - The data of the previous page (relative to `current_page`)
235-
* `{{ current_page }}` - The data of the current page (see `{{ pages }}` above)
236-
* `{{ next_page }}` - The data of the next page (relative to `current_page`)
237-
238-
Pages can be used like the following:
239-
240-
<ul class="nav">
241-
{% for page in pages if not page.hidden %}
242-
<li><a href="{{ page.url }}">{{ page.title }}</a></li>
243-
{% endfor %}
244-
</ul>
245-
246-
Besides using the `{{ pages }}` list, you can also access pages using Pico's
247-
page tree. The page tree allows you to iterate through Pico's pages using a tree
248-
structure, so you can e.g. iterate just a page's direct children. It allows you
249-
to build recursive menus (like dropdowns) and to filter pages more easily. Just
250-
head over to Pico's [page tree documentation][FeaturesPageTree] for details.
233+
* `{{ prev_page }}` - The data of the previous page, relative to `current_page`
234+
* `{{ current_page }}` - The data of the current page; refer to the "Pages"
235+
section below for details
236+
* `{{ next_page }}` - The data of the next page, relative to `current_page`
251237

252238
To call assets from your theme, use `{{ theme_url }}`. For instance, to include
253239
the CSS file `themes/my_theme/example.css`, add
254240
`<link rel="stylesheet" href="{{ theme_url }}/example.css" type="text/css" />`
255241
to your `index.twig`. This works for arbitrary files in your theme's folder,
256242
including images and JavaScript files.
257243

258-
Additional to Twigs extensive list of filters, functions and tags, Pico also
259-
provides some useful additional filters to make theming easier.
244+
Please note that Twig escapes HTML in all strings before outputting them. So
245+
for example, if you add `headline: My <strong>favorite</strong> color` to the
246+
YAML header of your page and output it using `{{ meta.headline }}`, you'll end
247+
up seeing `My <strong>favorite</strong> color` - yes, including the markup! To
248+
actually get it parsed, you must use `{{ meta.headline|raw }}` (resulting in
249+
the expected <code>My **favorite** color</code>). Notable exceptions to this
250+
are Pico's `content` variable (e.g. `{{ content }}`), Pico's `content` filter
251+
(e.g. `{{ "sub/page"|content }}`), and Pico's `markdown` filter, they all are
252+
marked as HTML safe.
253+
254+
#### Dealing with pages
255+
256+
There are several ways to access Pico's pages list. You can access the current
257+
page's data using the `current_page` variable, or use the `prev_page` and/or
258+
`next_page` variables to access the respective previous/next page in Pico's
259+
pages list. But more importantly there's the `pages` function. No matter how
260+
you access a page, it will always consist of the following data:
261+
262+
* `{{ id }}` - The relative path to the content file (unique ID)
263+
* `{{ url }}` - The URL to the page
264+
* `{{ title }}` - The title of the page (`Title` YAML header)
265+
* `{{ description }}` - The description of the page (`Description` YAML header)
266+
* `{{ author }}` - The author of the page (`Author` YAML header)
267+
* `{{ date }}` - The date of the page (`Date` YAML header)
268+
* `{{ date_formatted }}` - The formatted date of the page as specified by the
269+
`date_format` parameter in your `config/config.yml`
270+
* `{{ time }}` - The [Unix timestamp][UnixTimestamp] derived from the page's
271+
date
272+
* `{{ raw_content }}` - The raw, not yet parsed contents of the page; use the
273+
filter to get the parsed contents of a page by passing
274+
its unique ID (e.g. `{{ "sub/page"|content }}`)
275+
* `{{ meta }}` - The meta values of the page (see global `{{ meta }}` above)
276+
* `{{ prev_page }}` - The data of the respective previous page
277+
* `{{ next_page }}` - The data of the respective next page
278+
* `{{ tree_node }}` - The page's node in Pico's page tree; check out Pico's
279+
[page tree documentation][FeaturesPageTree] for details
280+
281+
Pico's `pages()` function is the best way to access all of your site's pages.
282+
It uses Pico's page tree to easily traverse a subset of Pico's pages list. It
283+
allows you to filter pages and to build recursive menus (like dropdowns). By
284+
default, `pages()` returns a list of all main pages (e.g. `content/page.md` and
285+
`content/sub/index.md`, but not `content/sub/page.md` or `content/index.md`).
286+
If you want to return all pages below a specific folder (e.g. `content/blog/`),
287+
pass the folder name as first parameter to the function (e.g. `pages("blog")`).
288+
Naturally you can also pass variables to the function. For example, to return a
289+
list of all child pages of the current page, use `pages(current_page.id)`.
290+
Check out the following code snippet:
291+
292+
<section class="articles">
293+
{% for page in pages(current_page.id) if not page.hidden %}
294+
<article>
295+
<h2><a href="{{ page.url }}">{{ page.title }}</a></h2>
296+
{{ page.id|content }}
297+
</article>
298+
{% endfor %}
299+
</section>
300+
301+
The `pages()` function is very powerful and also allows you to return not just
302+
a page's child pages by passing the `depth`, `depthOffset` and `offset` params.
303+
For example, if you pass `pages(depthOffset=-1)`, the list will also include
304+
Pico's main index page (i.e. `content/index.md`). This one is commonly used to
305+
create a theme's main navigation. If you want to learn more, head over to
306+
Pico's complete [`pages` function documentation][FeaturesPagesFunction].
307+
308+
#### Twig filters and functions
309+
310+
Additional to [Twig][]'s extensive list of filters, functions and tags, Pico
311+
also provides some useful additional filters and functions to make theming
312+
even easier.
260313

261314
* Pass the unique ID of a page to the `link` filter to return the page's URL
262315
(e.g. `{{ "sub/page"|link }}` gets `%base_url%?sub/page`).
316+
* You can replace URL placeholders (like <code>&#37;base_url&#37;</code>) in
317+
arbitrary strings using the `url` filter. This is helpful together with meta
318+
variables, e.g. if you add <code>image: &#37;assets_url&#37;/stock.jpg</code>
319+
to the YAML header of your page, `{{ meta.image|url }}` will return
320+
`%assets_url%/stock.jpg`.
263321
* To get the parsed contents of a page, pass its unique ID to the `content`
264322
filter (e.g. `{{ "sub/page"|content }}`).
265-
* You can parse any Markdown string using the `markdown` filter (e.g. you can
266-
use Markdown in the `description` meta variable and later parse it in your
267-
theme using `{{ meta.description|markdown }}`). You can pass meta data as
268-
parameter to replace <code>&#37;meta.&#42;&#37;</code> placeholders (e.g.
269-
`{{ "Written *by %meta.author%*"|markdown(meta) }}` yields "Written by
270-
*John Doe*").
323+
* You can parse any Markdown string using the `markdown` filter. For example,
324+
you might use Markdown in the `description` meta variable and later parse it
325+
in your theme using `{{ meta.description|markdown }}`. You can also pass meta
326+
data as parameter to replace <code>&#37;meta.&#42;&#37;</code> placeholders
327+
(e.g. `{{ "Written by *%meta.author%*"|markdown(meta) }}` yields "Written by
328+
*John Doe*"). However, please note that all contents will be wrapped inside
329+
HTML paragraph elements (i.e. `<p>…</p>`). If you want to parse just a single
330+
line of Markdown markup, pass the `singleLine` param to the `markdown` filter
331+
(e.g. `{{ "This really is a *single* line"|markdown(singleLine=true) }}`).
271332
* Arrays can be sorted by one of its keys using the `sort_by` filter
272333
(e.g. `{% for page in pages|sort_by([ 'meta', 'nav' ]) %}...{% endfor %}`
273334
iterates through all pages, ordered by the `nav` meta header; please note the
@@ -285,18 +346,6 @@ provides some useful additional filters to make theming easier.
285346
Twig! Simply head over to our [introductory page for accessing HTTP
286347
parameters][FeaturesHttpParams] for details.
287348

288-
You can use different templates for different content files by specifying the
289-
`Template` meta header. Simply add e.g. `Template: blog` to the YAML header of
290-
a content file and Pico will use the `blog.twig` template in your theme folder
291-
to display the page.
292-
293-
Pico's default theme isn't really intended to be used for a productive website,
294-
it's rather a starting point for creating your own theme. If the default theme
295-
isn't sufficient for you, and you don't want to create your own theme, you can
296-
use one of the great themes third-party developers and designers created in the
297-
past. As with plugins, you can find themes in [our Wiki][WikiThemes] and on
298-
[our website][OfficialThemes].
299-
300349
### Plugins
301350

302351
#### Plugins for users
@@ -429,6 +478,7 @@ url.rewrite-if-not-file = (
429478
For more help have a look at the Pico documentation at http://picocms.org/docs.
430479

431480
[Pico]: http://picocms.org/
481+
[PicoTheme]: https://github.com/picocms/pico-theme
432482
[SampleContents]: https://github.com/picocms/Pico/tree/master/content-sample
433483
[Markdown]: http://daringfireball.net/projects/markdown/syntax
434484
[MarkdownExtra]: https://michelf.ca/projects/php-markdown/extra/
@@ -438,6 +488,7 @@ For more help have a look at the Pico documentation at http://picocms.org/docs.
438488
[Composer]: https://getcomposer.org/
439489
[FeaturesHttpParams]: http://picocms.org/in-depth/features/http-params/
440490
[FeaturesPageTree]: http://picocms.org/in-depth/features/page-tree/
491+
[FeaturesPagesFunction]: http://picocms.org/in-depth/features/pages-function/
441492
[WikiThemes]: https://github.com/picocms/Pico/wiki/Pico-Themes
442493
[WikiPlugins]: https://github.com/picocms/Pico/wiki/Pico-Plugins
443494
[OfficialThemes]: http://picocms.org/themes/

0 commit comments

Comments
 (0)