RolandDreger / kirby-data-importer

Kirby 3 plugin for data import and generating subpages
MIT License
12 stars 0 forks source link

Kirby Data Importer (BETA, Version 1.0)

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.

Preview (on Vimeo)

Vimeo video to Kirby Plugin Data Importer

This plugin imorts data from a CSV file and creates subpages of it.


1. Installation

Download and copy this repository to /site/plugins/data-importer

Or you can install it with composer: composer require rd/data-importer

2. Usage

2.1 Insert field

Blueprint of preferred main page

fields:
  import_data:
    type: import_data

2.2 Define field labels

    button_headline: "Data Import"
    button_label: "Select data file ..."
    button_help: ""
    options_headline: "Options"
    options_help: ""

2.3 Set visibility of options field

    options_disabled: false

2.4 Define page section

For reload page section after generate subpages.

    subpage_section: "pages"

2.5 Define template for generated subpages

Name of php file in /site/templates

    subpage_template: "subpage"

2.6 Set status for generated subpages

Values: »listed«, »unlisted« or »draft«

    subpage_status: "unlisted"

2.7 Define field names for subpage title

Array of strings: Column labels in CSV table (see 3.2 Data file)

    title_key_array: ["first_name","last_name"]

2.8 Slug of image page (optional)

The images can be uploaded to a separate page and fetched from there.

    image_page_slug: "image-files"

2.9 Name of image field (optional)

Field name in blueprint of main page

    image_field_name: "portrait"

3. Examples

3.1 Blueprint Main Page

Page with import data field

fieldpage.yml

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"

3.2 Data file

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).

data_file.csv

first_name last_name jobtitle company street postcode state phone fax email 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

3.3 Blueprint Subpages

Pages that are populated with data from the CSV file.

subpage.yml

    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  

4 Options

You can find these settings in the file index.php

4.1 Default import mode

Values: »update« or »skip«. Setting if options field is hidden or value is unset.

'default_import_mode' => 'skip' 

4.2 Field separator in CSV file

Image name separator in CSV file is »,« (without space). Do NOT use »,« here!

'delimiter' => ";"

5. Credits

Based on Kirby CSV Handler (Kirby 2) with some inspirations from Plugin Kirby Link Field and other great plugins. Thanks to all!

6. Notice

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.

7. License

MIT

8. Authors

Roland Dreger, www.rolanddreger.net

PayPal Link