Kirby 3 plugin for data import and generating subpages
Note: Unfortunately this plugin no longer works with the current version of Kirby. I hope to find time to update it soon.
This plugin imorts data from a CSV file and creates subpages of it.
Download and copy this repository to /site/plugins/data-importer
Or you can install it with composer: composer require rd/data-importer
Blueprint of preferred main page
fields:
import_data:
type: import_data
button_headline: "Data Import"
button_label: "Select data file ..."
button_help: ""
options_headline: "Options"
options_help: ""
options_disabled: false
For reload page section after generate subpages.
subpage_section: "pages"
Name of php file in /site/templates
subpage_template: "subpage"
Values: »listed«, »unlisted« or »draft«
subpage_status: "unlisted"
Array of strings: Column labels in CSV table (see 3.2 Data file)
title_key_array: ["first_name","last_name"]
The images can be uploaded to a separate page and fetched from there.
image_page_slug: "image-files"
Field name in blueprint of main page
image_field_name: "portrait"
Page with import data field
title: Field page
preset: page
fields:
import_data:
type: import_data
button_headline: "Data Import"
button_label: "Select data file ..."
button_help: ""
options_disabled: false
options_headline: "Options"
options_help: ""
#Page section with generated subpages (for reload)
subpage_section: "pages"
# Template for generated subpages
subpage_template: "subpage"
# Status for subpages (Values: »listed«, »unlisted« or »draft«)
subpage_status: "unlisted"
# Field names for subpage title (Array of strings: Column labels in CSV table)
title_key_array: ["first_name","last_name"]
# Slug of image page (optional)
image_page_slug: "image-files"
# Name of image field (optional)
image_field_name: "portrait"
The field names in the blueprint for subpages correspond to the column labels in the CSV table. If there is more than one image, the image file names are separated by commas (without spaces).
first_name | last_name | jobtitle | company | street | postcode | state | phone | fax | website | portrait | ||
Michael | Collins | Command Module Pilot | NASA Headquarters | 300 E. Street SW, Suite 5R30 | DC 20546 | Washington | (202) 358-0001 | (202) 358-4338 | michael.colli ns@nasa.gov | https://www.nasa.gov | michael_collins.jpg | |
Edwin E. | Aldrin | Lunar Module Pilot | NASA Headquarters | 300 E. Street SW, Suite 5R30 | DC 20546 | Washington | (202) 358-0001 | (202) 358-4338 | edwin.e.aldrin@nasa.gov | https://www.nasa.gov | buzz_aldrin.jpg | |
Neil A. | Armstrong | Commander | NASA Headquarters | 300 E. Street SW, Suite 5R30 | DC 20546 | Washington | (202) 358-0001 | (202) 358-4338 | neil.a.armstrong@nasa.gov | https://www.nasa.gov | neil_armstrong.jpg |
Pages that are populated with data from the CSV file.
columns:
# Portrait
image:
width: 1/4
sections:
image:
type: fields
fields:
portrait:
type: files
label: Portrait
layout: cards
size: tiny
query: site.find('image-files').images
max: 1
image:
cover: true
ratio: 1/1
multiple: false
# Data input
data:
width: 3/4
sections:
content:
type: fields
fields:
first_name:
type: text
label: First Name
width: 1/2
last_name:
type: text
label: Last Name
width: 1/2
jobtitle:
type: text
label: Job Title
width: 1/1
company:
type: text
label: Company
width: 1/1
street:
type: text
label: Street
width: 1/1
postcode:
type: text
label: ZIP
width: 1/3
state:
type: text
label: State
width: 2/3
phone:
type: tel
label: Phone
width: 1/2
fax:
type: tel
label: Fax
width: 1/2
email:
type: text
label: Email
width: 1/1
placeholder: ""
icon: email
website:
type: text
label: Website
before: https://
placeholder: ""
icon: url
You can find these settings in the file index.php
Values: »update« or »skip«. Setting if options field is hidden or value is unset.
'default_import_mode' => 'skip'
Image name separator in CSV file is »,« (without space). Do NOT use »,« here!
'delimiter' => ";"
Based on Kirby CSV Handler (Kirby 2) with some inspirations from Plugin Kirby Link Field and other great plugins. Thanks to all!
This plugin is provided »as is«. Use it at your own risk. Please test the plugin carefully before using it in your production environment.
Feedback is welcome.
Roland Dreger, www.rolanddreger.net
PayPal Link