Move Pages Plugin

Move Pages Plugin

Missing move pages feature for Kirby 3. You can move the pages under the parent pages you specify with this plugin.

Installation

  1. Download the latest release
  2. Unzip downloaded file
  3. Copy/paste unzipped folder in your /site/plugins folder

Usage

Don’t forget! To move a page under the another page, the parent page must support the page template you are moving. This option must be a query language string or an array of templates and must be a collection of pages, not a single page.

Templates

Simply specify under which parent templates a page can be moved.

# /site/blueprints/pages/project.yml
title: Project

options:
    # parent page templates where you can move this page
    move:
        - projects
        - portfolio

Query language

If you need a more complex logic or dynamic parent templates, you can use the query language.

# /site/blueprints/pages/project.yml
title: Project

options:
    # parent pages collection where you can move this page
    move: site.children.filterBy('template', 'in', ['projects', 'portfolio'])

Hooks

Available hooks for this plugin: page.move:before and page.move:after.

// /site/config/config.php
return [
    'hooks' => [
        'page.move:before' => function (Kirby\Cms\Page $page, ?Kirby\Cms\Page $parent = null) {
            // your code goes here
        },
        'page.move:after' => function (Kirby\Cms\Page $newPage, Kirby\Cms\Page $oldPage, ?Kirby\Cms\Page $parent = null) {
            // your code goes here
        }
    ]
];

Sample use case: shop

For example, let’s assume that there is a multi-category structure on a shop site. You want to move a product to another category.

Content directory

  • /home
  • /about
  • /shop
    • /category-a
      • Product A
    • /category-b
      • Product B
    • /category-c
      • Product C
  • /contact

You can set move option with category template:

# /site/blueprints/pages/product.yml
title: Product item

options:
    move:
        - category

Or you can use query language:

# /site/blueprints/pages/product.yml
title: Product item

options:
    move: kirby.page('shop').children

Version 2.1.0

:tada: Features

  • Added new hooks for the plugin: page.move:before and page.move:after.
1 Like

Love the hooks feature! :slight_smile:

Version 2.2.0

:sparkles: Enhancements

  • Supports moving pages to or from to root (site blueprint)

:bug: Fixes

  • Fixed moving top root pages that have no parent

:warning: Breaking Changes

  • parent hook argument can be null (nullable) when page model have no parent

Newbie question : how to handle a case where the catalog have multiple categories > sub categories > sub sub categories ? Currently the plugin only scan children at one level deep.

The plugin;

  • If you define pages templates it will scan the whole site.
  • If you define a query, it will only return the response of your query.

Please let me know your use case to help you.

Given the following document tree,



/home
/about
/documents
    /category-a
        Product A
        /category-a-a
            Product PAA
            /category-a-a-a
                Product PAAA
    /category-b
        Product B
        /category-b-b
            Product BB
            ..
    /category-c
        Product C
/contact


How to allow page Product C to be moved in the same category as product PAA ?

As far I understand your use case, you can try like following. Just add your category blueprint name into your product blueprint options.

# /site/blueprints/pages/product.yml
title: Product

options:
    # parent page templates where you can move this page
    move:
        - category

Thanks for your help. Setting the move options to the template name did the trick.