Download the PHP package madebyraygun/craft-block-loader without Composer

On this page you can find all versions of the php package madebyraygun/craft-block-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craft-block-loader

Craft Block Loader

This is a context loader for Craft CMS matrix blocks and nested entries. Use this plugin in conjunction with the Craft Component Library to format your block context to work with your component library.

See a sample implementation in the Craft Component Library Demo repository.

Requirements

This plugin requires Craft CMS 5.0 or later, and PHP 8.2 or later.

Installation

This plugin is not available in the Craft Plugin Store, but is published on Packagist and can be installed with Composer.

From the terminal:

Configuration

By default, the plugin will initialize all block class definitions using the namespace modules\blocks in the craft/modules/blocks directory so make sure you have the proper autoloading config in place. Where you tipically would have:

ContextBlock classes work outside the module initialization logic from CraftCMS but it is expected to have compliance with the PSR-4 standard on the directory structure you define. To change these defaults, create a block-loader.php file in your Craft config directory to change this directory.

Sample config:

Scan New Files

Available ContextBlock classes are automatically detected based on the namespace you define, but the autoloader will not pick up file changes until you regenerate the autoloader class map, which you can do by running composer dump-autoload -a. This can be a bit cumbersome during development. Instead, you can set the scanNewFiles setting to true, and the plugin will scan the directory for new files on every request. Just note that this is not recommended for production environments since performance can be affected.

Usage

Each class defined using the provided namespace modules\blocks is paired with each entry block inside a Matrix Field or a Ckeditor Field using their block handle. You need to extend from the ContextBlock class and implement the getContext method to return the context data for your block.

Example: AnchorBlock.php

Not very exciting, but hopefully you see that this gives you the opportunity to return an any custom data you want for your block content.

More complex examples can extend the ContextBlockSettings class to change the settings on a per-block basis. Settings options include:

In your entry template

Cache

The plugin will cache all blocks defined as cacheable in the context block settings. This will improve performance for blocks that don't change its context on a per-request basis. The blocks cache is cleared every time an Entry is saved, affecting only the blocks that are related to the saved entry.

If you need to clear the cache globally for all entries, you can do so from the Craft Control Panel under the Utilities > Caches > Blocks context data item or by running the php craft clear-caches/block-loader command from the terminal.

Additionally you can disable the caching for all blocks entirely by setting the enableCaching setting to false in the block-loader.php config file. This is useful for development environments where you want to see changes to your blocks immediately. But you may want to enable caching in production to improve performance.

Expired entries

When an asset or an entry is saved, the cache is automatically cleared for related entries, but this action doesn't run when an entry expires rather than being saved. If you use the expiration feature and are concerned about expired entries showing up in related content blocks, use the console command craft block-loader/expire-cache to clear the block-loader cache specifically for entries that are related to entries that have expired since the last time the command was run.

Ckeditor Fields

You can call blocksFromField function on an entry indistinctly of the field type (Matrix or Ckeditor). The plugin will automatically detect the field type and return the blocks in the same format. However, for Ckeditor fields the markup is by default wrapped as a block, you can pass the context into a specific component or just render the markup directly.

For more advance preprocessing on the markup context blocks you can create your own class extending from ContextBlock class and implementing the getMarkupContext method. For this class to be automatically called the fieldHandle setting must be set to markup. Or just name the class MarkupBlock and the plugin will automatically derive the template handle from the class name as markup.

Nested entries within a matrix field

If you're using the CKEditor nested entries feature within another matrix field, be sure to extract the context for the nested entries within the context for that block:

The markup for your rich text component will look similar to the CkEditor example above:


All versions of craft-block-loader with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2.0
craftcms/cms Version ^5.0
composer/class-map-generator Version ^1.3.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package madebyraygun/craft-block-loader contains the following files

Loading the files please wait ....