定制 linkorb/custom-element 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

linkorb/custom-element

Composer 安装命令:

composer require linkorb/custom-element

包简介

Custom element

README 文档

README

This library allows you to define custom elements for usage in (Twig) templates.

Think of it as light-weight SSR (Server Side Rendererd) Web Components.

For example, you can create a new element such as <Avatar username="alice" imageUrl="https://example.web/alice.webp" bio="Hello world" />

Then you define a twig template elements/Avatar.html.twig such as the following:

<div class="card avatar">
  <div class="card-body">
    <h1>{{username}}</h1>
    {% if imageUrl is defined %}
      <img src="{{ imageUrl }}" class="avatar-image" />
    {% endif %}
    {% if bio is defined %}
      <small>{{ bio }}</small>
    {% endif %}
  </div>
</div>

Your custom element can now be rendered using your custom element template. The template receives a variable for every specified attribute.

Custom elements will only be rendered if they start with an upper-case character (to distinguish standard from custom elements)

Usage

Symfony

Add the following to your services.yaml to register the renderer and the twig extension:

services:
    LinkORB\Component\CustomElement\Twig\CustomElementExtension:
        tags: ['twig.extension']
    LinkORB\Component\CustomElement\CustomElementRenderer: ~

The renderer

You can turn any raw HTML with custom elements into a rendered HTML output like this:

$renderer = new Renderer($twig);
$html = $renderer->render($htmlWithCustomElements);

The Twig extension

You can render custom elements from any Twig template using the filter:

<h1>Example</h1
{{ html|custom_element_render|raw }}

License

MIT. Please refer to the license file for details.

Brought to you by the LinkORB Engineering team


Check out our other projects at linkorb.com/engineering.

Btw, we're hiring!

统计信息

  • 总下载量: 68
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固