Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Load layouts from /layouts #9

Merged
merged 6 commits into from
Apr 24, 2018
Merged

Load layouts from /layouts #9

merged 6 commits into from
Apr 24, 2018

Conversation

johanjanssens
Copy link
Member

@johanjanssens johanjanssens commented Apr 23, 2018

If a layout is defined in the page frontmatter of a page it's loaded from the /layouts folder. If no layout is defined the default layout that is part of the component is loaded.

The layout supports any properties. Properties are defined in the frontmatter using YAML. All properties are accessible in the page templates using $[property]. Properties should be lowercase.

Loading

The layout is is a relative path and can include subfolders. Example

  • layout: file
  • layout: folder/file

The layout follows the same naming conventions as the page, and is auto-discovered. The specific template engine is loaded based on the filename suffix.

File Naming

The file extension should be the layout format, suffixed with the template engine used to render the layout.

  • mypage.html.php (php engine)
  • mypage.html.md (markdown engine)

Properties

A layout can have frontmatter, the frontmatter becomes available as PHP variables in the layout. The 'page' variable is reserved and cannot be used in the frontmatter.

An additional $page variable is available which gives direct access to all the page properties, and is readable and writable.

See:h ttps://github.com//pull/6

Inheritance

When a layout specifies another layout, it means the content of the first layout will be injected into the ktml:content tag of the second layout. As an analogy, think of Russian dolls that fit into each other. Each layout fits into another layout that it specifies. See: https://jekyllrb.com/tutorials/convert-site-to-jekyll/#how-layouts-work

At the same time the frontmatter of the layouts will be merged, if an inner layout specifies the same variable as an outer layout, the outer layout will receive the value defined in the inner layout. This allows to use frontmatter to dynamically adjust the behavior of the outer layout.

Notes

  1. As part of this change page template files no longer require to have a format suffix eg '.html'.

  2. This PR allows makes it possible to use <ktml:content> in a layout to render the content of the page.

  3. As part of this change the module filter is now also available, this means that you can make use of the<ktml:module position="[position]">[content]</ktml:module>syntax to insert modules on the fly. The module filter should also be documented as it's very powerful. Code can be found here: koowa/template/filter/module.php

  4. It's now also possible to use import to import the content of none renderable files. Supported types are: html, css, js and svg. Example <?= import'('path/to/image.svg) ?>

@johanjanssens johanjanssens added this to the 0.1 milestone Apr 23, 2018
@johanjanssens johanjanssens self-assigned this Apr 23, 2018
@johanjanssens johanjanssens requested a review from raeldc April 23, 2018 22:15
@raeldc raeldc mentioned this pull request Apr 24, 2018
62 tasks
@johanjanssens johanjanssens merged commit c200085 into master Apr 24, 2018
@johanjanssens johanjanssens deleted the feature/8-layout branch April 24, 2018 15:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant