Download the PHP package hananils/kirby-tree-methods without Composer

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

Tree Methods is a plugin for Kirby 3 to convert field values to HTML and adapt the resulting markup by changing headline hierarchy, wrapping and filtering elements, manipulating tag names, add classes or other attributes. The main purpose of the plugin is to take the field markup, that usually is a static string returned by a formatter, and help web designers to tailor it the way they need it and to apply typographic tweaks. Therefor is allows for:

  1. [selecting and filtering content](),
  2. [manipulating the resulting markup](),
  3. [outputing HTML]().

The plugin works with all Kirby fields that allow for the generation of valid HTML, like Blocks or textareas. It also accepts custom methods to convert field values to HTML.

Examples

Manipulating the headline hierarchy

Content:

Template:

Output:

Manipulating markup using snippets

Content:

Template:

Snippets /site/snippets/elements/p.php:

Output:

Changing elements

Field value:

Template:

Output:

Wrapping Elements

Field value:

Template:

Output:

Installation

Download

Download and copy this repository to /site/plugins/tree-methods.

Git submodule

Composer

Field Methods

Under the hood, the plugin converts the HTML string to DomDocument using DomDocument->loadHTML(). The content is expected to the encoded using UTF8. XPath is used to filter and find elements in the tree, see https://en.wikipedia.org/wiki/XPath#Syntax_and_semantics_(XPath_1.0).

toTree($formatter)

Converts the field value to a DOM tree using the given formatter.

A global default can be set by defining hananils.tree.formatter in the configuration.

Selections

Given a field named text and $tree = $page->text()->toTree():

$tree->select($xpath)

Selects all elements matching the given xPath query.

$tree->first()

Selects the first element.

$tree->last()

Selects the last element.

$tree->nth($position)

Selects the nth element.

$tree->limit($number)

Limits the current selection to the given number.

$tree->offset(1)

Offsets the current selection by the given number.

$tree->clear()

Clears the current selection and selects all nodes again (keeping all manipulations).

$isEmpty()

Returns true is the current selection is empty.

$isNotEmpty()

Returns true is the current selection is not empty.

has($query)

Returns true is the current selection contains the given element.

count()

Counts the nodes in the current selection.

Manipulations

Given a field named text and $tree = $page->text()->toTree():

$tree->level($start)

Adjusts the headline hierarchy to start at the given level.

$tree->select($xpath)->setName($name)

Selects all elements matching the given xPath query and updates the element names.

$tree->select($xpath)->setAttribute($attribute, $value)

Selects all elements matching the given xPath query and sets the given attribute.

$tree->wrap($element, $from, $name, $attributes)

Wraps all elements (from … to) in the given element, adding attributes if defined.

$tree->wrapText($string, $element, $attributes)

Wraps all text occurences of the string in the given element, adding attributes if defined.

snippets($path, $data)

Apply a snippet to each element in the current selection. Looks for a snippet with the name of the element first, uses a snippet named default second or leaves the element unchanged if none is found.

By default, each snippet gets this data passed:

See example in the introduction.

widont()

Improved version of the Kirby method, taking the DOM into account.

excerpt()

Alias for the Kirby method.

kirbytextinline()

Improved version of the Kirby method, taking the DOM into account.

smartypants()

Improved version of the Kirby method, taking the DOM into account.

Output

Given a field named text and $tree = $page->text()->toTree():

$tree->html($clear)

Returns the HTML of the current selection.

$tree->content($clear)

Returns the content of the current selection (text and child nodes).

$tree->text($clear)

Returns the text value of the current selection.

$tree->toDocument()

Returns the DomDocument object.

$tree->toSelection()

Returns the DomNodeList of the current selection.

$tree->toField($type)

Returns the field instance with the field value set to the current html (default), content or text value.

License

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


All versions of kirby-tree-methods with dependencies

PHP Build Version
Package Version
Requires getkirby/composer-installer Version ^1.1
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-tree-methods contains the following files

Loading the files please wait ....