Download the PHP package hananils/kirby-attrs-helper without Composer

On this page you can find all versions of the php package hananils/kirby-attrs-helper. 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 kirby-attrs-helper

Setting attributes on elements in snippets and templates quickly becomes convoluted. This gets worse if attributes require additional logic, like conditionally adding segmented values like classnames or datasets. Attributes helper mitigates this issue by offering a simple interface to set attributes.

Usage

Attributes helper takes an associative array with the keys specifying the attribute names and the values specifying the corresponding attribute values. Values can either be static if passed as string or conditional if passed as array.

Static values

If values are passed as string, the plugin will create an attribute for each key using the given value.

This will create the following markup:

Conditional values

The attribute values can also be constructed conditionally:

This will only add the id attribute if the current page is the homepage. Otherwise, the attribute will be omitted.

Boolean values

If values evaluate to a boolean value, an attribute is only rendered if its value is true. In the following case, the checked attribute will only be added if the page is listed.

The result will either be a checked or unchecked checkbox:

Segmented values

If the value itself is an array, all keys will be considered value segments that will be joined by as separator (a space by default). The associated array value is used as the condition to determine whether a segment should be added to the attribute or skipped.

This is useful if you’d like to set classnames or datasets dynamically.

The following example will either create a class attribute with the value published has-image, published, has-image or none at all depending on the page settings:

The helper also allows you to combine static and dynamic segments:

In this case, some static classnames will always be added to the class attribute.

Custom delimiter

If you’d like to join segmented values with a custom delimiter, you can pass it as second argument to the attrs function:

This example will return some|static|values as value for the data-list attribute.

Installation

By default, plugins in Kirby reside in a special folder located at /site/plugins. Each plugin is installed in its proprietary subfolder. This installation can be handled in four different ways: you can either install them manually or manage them using Kirby CLI, Git submodules or Composer. You can install Attributes Helper either way and should choose the method suiting your project best.

Please note that all examples given here assume you are using the default plugin root. If you changed your plugin root, e. g. with a custom folder setup, you’ll also have to adjust the paths given in this guide. For further information on how to manage plugins, please read the official Kirby plugin introduction.

Download

Download and copy this repository to /site/plugins/attrs-helper.

Kirby CLI

Git submodule

Composer

Documentation

Where possible, files contain inline annotations. For extended documentation, please visit our dedicated plugin site at kirby.hananils.de/​plugins/​attrs-helper.

Cookbook

Reference

License

This plugin is provided freely under the MIT license by hana+nils · Büro für Gestaltung. We create visual designs for digital and analog media.


All versions of kirby-attrs-helper with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
getkirby/composer-installer Version ^1.2
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 hananils/kirby-attrs-helper contains the following files

Loading the files please wait ...