ether/atom
Composer 安装命令:
composer require ether/atom
包简介
Adding enhanced modularity to Craft CMS Twig templating
README 文档
README
Adding enhanced modularity to Craft CMS Twig templating
Installation
$ composer require ether/atom
Usage
Create a folder called _atoms in your templates directory (this can be
customised, see Config).
Basic
In this folder you can create re-usable twig templates, or atoms (a.k.a. modules, components, molecules). You can access the atoms in twig using the following syntax:
{% x:my-atom %}
The above will include _atoms/my-atom in your template. If my-atom
doesn't exist then nothing will be output.
Parameters
You can pass parameters to your atom which will be exposed within the atom. The current template context is NOT passed to the atom, so any variables defined outside will have to be passed manually.
{% x:my-atom { heading: "Hello world!" } %}
In the above example, my-atom will be given access to the heading variable.
If heading isn't passed then the variable will be undefined. You'll want to
check variable availability with is defined or |default.
Children
Children can also be passed to atoms:
{% x:my-atom { heading: "Hello world!" } %}
<p>This is my atom</p>
<p>There are many like it, but this is mine</p>
<p>{{ myVariable }}</p>
{% endx:my-atom %}
Children are rendered in the parent context, not the atoms. This means any variables you pass to the atom will not be available in the children (unless they are also available in the parent context).
Children are rendered within the atom using the children variable, which will
contain the rendered contents of the children or null if no children are
defined.
{# Contents of `_atoms/my-atom` #} <div> <h1>{{ heading }}</h1> {{ children }} </div>
Nested
Atoms can be nested inside other atoms!
{% x:my-atom %}
{% x:another-atom %}
{% endx:my-atom %}
Sub-folders
You can store atoms in folders within your _atoms directory. For example, if
you had an atom at _atoms/cards/news, you could access it using the following
syntax:
{% x:cards/news %}
Dynamic Atoms
You can render atoms with dynamic names by wrapping the atom name in square brackets:
{% set myVar = 'example-atom' %}
{% x:[myVar] %}
{% x:[myVar] %}
<p>hello world!</p>
{% endx:[myVar] %}
Config
You can configure Atom by creating a atom.php file in your config folder.
See config.php for the available settings.
ether/atom 适用场景与选型建议
ether/atom 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.28k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2021 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ether/atom 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ether/atom 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-12
