定制 lmc/twigx-bundle 二次开发

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

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

lmc/twigx-bundle

最新稳定版本:5.0.1

Composer 安装命令:

composer require lmc/twigx-bundle

包简介

This is Symfony bundle which extends the twig implementation by an JSX like syntax.

README 文档

README

Latest Stable Version Coverage Status

Symfony bundle extending Twig template engine with JSX-like markup.

Requirements

  • PHP ^8.1
  • Symfony ^5.4 || ^6.4 || ^7.2
  • Twig ^3

Changelog

See CHANGELOG

How to install

Step 1

Download using composer

Install package

composer require almacareer/twigx-bundle

Step 2

Add TwigXBundle into bundles (under all bundles). If you use Symfony flex, it will be configured automatically.

bundles.php

    return [
        ...,
        AlmaCareer\TwigXBundle\TwigXBundle::class => ['all' => true],
    ];

Step 3 (optional)

If you want to change the default settings, create a config

config/packages/twigx.yml

    # all parameters are optional
    twigx:
        # define one or more paths to expand or overload components (uses glob patterns)
        paths:
            - "%kernel.project_dir%/templates/components"
        paths_alias: 'jobs-ui' # alias for twig paths above (default is 'spirit')

Usage

Now you can use Twig components with HTML-like syntax in your Symfony project. You only need to remember that, unlike in HTML, component tags must always start with a capital letter:

<ComponentName attr="value">Some other content</ComponentName>
  ...
<ComponentName attr="value" />

You can pass attributes like this:

<ComponentName
:any="'any' ~ 'prop'" // this return as "any" prop with value "anyprop"
other="{{'this' ~ 'works' ~ 'too'}}"
anotherProp="or this still work"
not-this="{{'this' ~ 'does'}}{{ 'not work' }}" // this returns syntax as plain text but prop with dash work
ifCondition="{{ variable == 'success' ? 'true' : 'false' }}"  // condition can only be written via the ternary operator
jsXCondition={ variable == 'success' ? 'true' : 'false' }  // condition can only be written via the ternary operator
isBoolean={false}  // if value is false
numberValue={11}  // if value is number 11
isOpen  // if no value is defined, it is set to true
>
    Submit
</ComponentName>

or pure original implementation

{% embed "@spirit/componentName.twig" with { props: {
    attr: 'value'
}} %}
    {% block content %}
        Some other content
    {% endblock %}
{% endembed %}

Allowed parenthesis

You can pass variables to props using two syntaxes. JSX-like syntax uses single {...} parentheses or Twig-like syntax that uses {{...}} parentheses. In both cases, there can be a whitespace around the value that is used. See the examples below.

JSX-like syntax example:

<ComponentName variable={value} anotherVariable={ value } />

Twig like syntax example:

<ComponentName variable={{value}} anotherVariable={{ value }} />

if you want to extend these components, an example guide is here. if you want to contribute, read guide here.

统计信息

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

GitHub 信息

  • Stars: 11
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固