Version 0.2
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 texnixe/kirby-csv-handler
- Clone or download this repository.
- Unzip the archive if needed and rename the folder to kirby-csv-handler.
Make sure that the plugin folder structure looks like this:
site/plugins/kirby-csv-handler/
If you know your way around Git, you can download this plugin as a submodule:
$ cd path/to/kirby-project
$ git submodule add https://github.com/texnixe/kirby-csv-handler site/plugins/kirby-csv-handler
- Create a new CsvHandler object:
$csv = csv($filepath, $parse_header = 'false', $delimiter = ',', $length = 8000);
- Create pages or structure field
// create pages
$csv->createPages($parent, $UIDKey, $template = 'default', $update = false);
$csv->createPages('products', 'ArticleNo', $template = 'default');
// create structure field
$csv->createStructure($uri, $field, $append = false);
$parent: path to parent page $UIDKey: Columnname you want to use as Page UID, must be unique $template: template to use for new pages $update: set whether or not to update an existing page with the new data
$uri: path to the page where the structure will be stored $field: name of the structure field $append: set whether or not to append new data, if set to false, all data will be replaced with the new data
The following options can or need to be set in your /site/config/config.php
file:
c::set('csv-handler.file.filepath', 'path/to/csv/file');
c::set('csv-handler.file.delimiter', ';');
c::set('csv-handler.page.uid', 'a_column_name');
c::set('csv-handler.page.update', false);
c::set('csv-handler.page.template', 'template_name');
c::set('csv-handler.structure.field', 'title');
c::set('csv-handler.structure.append', false);
Required. A valid path to a .csv file.
The delimiter between columns in your .csv file. Default delimiter is a comma (,).
A column name that will be used to create the UIDs of the new pages. If you use a column name that starts with a number, an underscore will be used as a prefix. The entries in this column must be unique, otherwise the new page will not be created, or - if csv-handler.page.update
is set to true
- another entry with the same value will overwrite the first.
If you want to create subpages from the lines in the .csv file, this options defines if existing pages should be updated with the data from the file. Default is false
.
Set the template for the subpages. Default is default
.
With this option you can set the field that is used for the structure field entries.
Set this option to true
to append all lines from the .csv file to an existing field if this exists. By default, the entries from the structure field will be overwritten with the entries of the .csv file.
The Kirby CSV-Handler Plugin currently provides two routes:
csv-handler/createpages/(:all)
csv-handler/createstructure/(:all)
where (:all)
is the path to the parent page (in case of subpage creation)/page (in case of structure field).
For example, the URL http://example.com/csv-handler/createpages/products
will create subpages in /content/products
, while http://example.com/csv-handler/createstructure/products
will create/update the structure field in /content/products
.
You must be logged in to use the routes.
http://www.opensource.org/licenses/mit-license.php
Sonja Broda https://www.texniq.de