Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ikkez/f3-template-sections

Section support for the F3 Template engine
https://github.com/ikkez/f3-template-sections

fat-free-framework templates

Last synced: 20 days ago
JSON representation

Section support for the F3 Template engine

Awesome Lists containing this project

README

        

# Template sections

This addon introduces *template inheritance* via **sections** for the [F3](https://github.com/bcosca/fatfree) template engine.

## Install

To install with composer, just run `composer require ikkez/f3-template-sections`.
In case you do not use composer, add the `src/` folder to your `AUTOLOAD` path or copy the files from `src/` into your libs.

## Initialize

To use the new directives, you need to register them:

Init:

```php
\Template\Tags\Section::init('section');
\Template\Tags\Inject::init('inject');
```

## Usage

Imagine this main site template:

```html


Site Name









```

You see we have create a section with `id=sidebar`. This section can contain default content already if you want,
but within `article.html` you can now inject content to the sidebar, which is actually in a parent level:

```html

Fear me parrot, ye evil whale!


All comrades sail gutless, stormy jacks. Ho-ho-ho! hunger of riddle.

Arrr, fine hunger!


What’s the secret to canned and sun-dried zucchini? Always use quartered rum.


```

That's basically it. There are some more modes for injecting content:

### Append / Prepend

In this example we have a breadcrumb navigation. You can change the generated tag-element with the `tag`-attribute.

```html


  • Home

  • ```

    By default the content in the section is replaced upon inject. If you wish, you just append the existing content like this:

    ```html

  • Wiki
  • ```

    You can also use `prepend` as inject mode.

    ### Rendering locally

    You can switch the model to use local variables instead of rendering the content in the injected section. This is useful when you iterate over an array of data within a `` block.

    ```html




    ```
    ## API

    ### section

    Attributes:

    * `section`
    Used to identify the new section.
    * `id`
    Alias to `section`, but the `id` attribute will be visible in the final markup.
    * `tag`
    The tag-element name of the final section. Default: `section`.
    When you set `tag="FALSE"`, the section content is not wrapped into any element.

    Any other attributes are just passed to the final tag element.

    ### inject

    Attributes:

    * `section`
    Used to identify the destination section.
    * `id`
    Alias to `section`.
    * `mode`
    The injection mode for content:
    **overwrite** (default): replaces the existing content in the section
    **append**: adds content after the existing content
    **prepend**: adds content before the existing content
    * `local`
    Render element locally with existing variables first

    ## Licence

    GPLv3