Git Product home page Git Product logo

kirby-modules's Introduction

Kirby Modules

module

Introduction to modules

What is a module?

A module is a regular page, differentiated from other pages by being inside a modules container. This approach makes it possible to use pages as modules without sacrificing regular subpages:

πŸ“„ Page
  πŸ“„ Subpage A
  πŸ“„ Subpage B
  πŸ—‚ Modules
    πŸ“„ Module A
    πŸ“„ Module B

Comparison to other approaches

You can also set up modular Kirby websites with a structure field or the builder plugin.

In comparison this approach offers some advantages:

  • Separate file pools
  • Better performance because of nesting
  • Anchor links out of the box
  • No issues with certain fields/plugins

How do I set up the templates/blueprints?

This plugin assumes you're going to use a module. prefix for your module blueprints. For example site/pages/module.text.yml. In there you can do anything you wantβ€”it's just a regular page.

On the modular (mother) pages you iterate over the modules inside the modules container like this:

<?php
  foreach($page->find("modules")->children()->listed() as $module) {
    snippet('modules/' . $module->intendedTemplate(), ['page' => $module])
  } 
?>

As you can see, the modules don't have templates and simply live in for example site/snippets/modules/module.text.php or site/snippets/modules/module.images.php.

Example installation

I put a simple example installation in a separate branch. Maybe this helps you getting started.

Features of this plugin

Modules section

The modules section adds some features to the core pages section:

  • Every blueprint starting with module. is available to create
  • The module blueprint title is displayed in the info
  • The parent is set to the modules container
  • The link to the modules container in the headline is disabled
  • Small style adjustments to differentiate it from pages

Using the modules section on a page will automatically trigger a built-in hook that creates the modules container page.

sections:
  modules:
    type: modules

Module models (sorry, that's what it's called)

To overwrite the module URL you'd have to add a page model for every single module. This plugin overwrites the URL of every module page from example.com/subpage-a/modules/text to example.com/subpage-a#text.

Module templates

This plugin adds templates with a redirection to the modules container and all the single modules. This way nobody can access the pages directly, not even by guessing the URLs.

Module blueprint

By adding extends: module/changeTemplate to the options of your module blueprints, every blueprint starting with module. is available to change to in the page options.

options:
  extends: module/changeTemplate

Options

By default, the module.text blueprint will be the first option when adding a module. You can set it to another blueprint in your site/config/config.php:

return [
  'medienbaecker.modules' => [
      'default' => 'module.text'
  ]
];

kirby-modules's People

Contributors

medienbaecker avatar schnti avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.