Version 0.2
This field work exactly like the structure field. In fact it's a copy of it with some important changes.
The Snippetfield does not use entry. Instead it uses snippets.
Use one of the alternatives below.
If you are using the Kirby CLI you can install this plugin by running the following commands in your shell:
$ cd path/to/kirby
$ kirby plugin:install jenstornell/kirby-snippetfield
kirby-snippetfield
.Make sure that the plugin folder structure looks like this:
site/plugins/kirby-snippetfield/
If you know your way around Git, you can download this plugin as a submodule:
$ cd path/to/kirby
$ git submodule add https://github.com/jenstornell/kirby-snippetfield site/plugins/kirby-snippetfield
style: items
(default)I used the example from the docs. I have replaced entry
with snippet
and added style: items
(just to make it clear).
fields:
addresses:
label: Addresses
type: snippetfield
snippet: mydir/snippet
style: items
fields:
street:
label: Street
type: text
zip:
label: ZIP
type: text
city:
label: City
type: text
The example above will use the snippet site/snippets/mydir/snippet.php
. You can change the path in the config.php
.
style: table
For the table style you need a snippet for every field.
fields:
addresses:
label: Addresses
type: snippetfield
style: table
fields:
street:
label: Street
type: text
snippet: mydir/snippet1
zip:
label: ZIP
type: text
snippet: mydir/snippet2
city:
label: City
type: text
snippet: mydir/snippet2
If you don't like the root path, you can change it in your config.php
:
c::set( 'snippetfield.path', kirby()->roots()->snippets() );
$page
objectAll the page variables are available through the $page
object and you can use them like this:
echo $page->title();
$field
objectTo give you a hint of what it contains, do this (might be slow or crash):
print_r( $field );
$style
stringIf for some reason you need to have the style value you can use that.
style: items
(default)If you use style: items
you also have access to the $values
object.
$values
objectBecause the output contains more than one field, all the field keys and values are in the $values
object.
print_r( $values );
style: table
If you use style: table
you also have access to the $value
string.
$value
stringBecause the output only contain one field, you only need a string and that is the $value
string.
style: table
exampleIn this case I have an image
field and the $value
will be filename.jpg
. It is actually using the thumbnail cache to generate and store a thumbnail of an image.
<img src="https://github.com/kirby-deprecated-plugins/kirby-snippetfield/raw/master/<?php echo thumb($page->image($value), array('width' => 150))->url(); ?>">
You now also have access to $key
which is the column slug.
0.2
$key
to style: table
which is the column slug.package.json
which means Kirby CLI support.0.1