承接 skrip42/static-collector-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

skrip42/static-collector-bundle

Composer 安装命令:

composer require skrip42/static-collector-bundle

包简介

add static collector for control you static!

README 文档

README

symfony bundle that simplifies the work with statics

premise:

Often your included widgets or custom form UI elements need their own styles and scripts. The standard statics connection system offers 3 options for their connection:

  • include statics in the template of a included widget or form element, which leads to duplicates and "splashing" of static across your final html
  • include all static in the constructor template, which makes control more difficult and violates the dependency principle
  • include all the statics in the base template, which leads to an unjustified increase in the size of the loaded statics and also violates the principle of dependencies

this bundle offers an alternative without these disadvantages

how in works:

The StaticCollector is a global storage. During template execution, scripts, styles and assets are registered in the StaticsCollector. After the template is compiled into html, the statics collector places the statics in the marked places

install:

composer require Skrip42/static-collector-bundle

usage:

  • just put "{% static_place 'script' %}" and "{% static_place 'style' %}" tags in your base template where you want to see your included scripts and styles:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}PonBase{% endblock %} - PonBase</title>
        <link rel="shortcut icon" href="{{ asset('images/favicon.ico') }}" type="image/x-icon">
        {% static_place 'style' %}
    </head>
    <body>
        ...
        {% static_place 'script' %}
    </body>
</html>
  • now you can connect statics in any template you use
{% block custom_input_for_example %}
  ...
  {% static 'some_webpack_asset' %}
  {% static 'https://external.com/script.js?may_have=parameters' %}
  {% static 'https://external.com/style.css?may_have=parameters' %}
{% endblock %}

advanced:

static type

you can specify which statics should be placed (styles, scripts or all)

    {% static_place 'style' %}
    {% static_place 'script' %}
    {% static_place 'all' %}

static order control

you can define the order of connecting statics, specifying it manually

  {% static 'some_important_static' order 0 %}

the order number must be any integer. By default all statics have the order number 1000

division static into group

you can mark statics as belonging to some group

  {% static 'some_static' group 'some_group' %}

  ...

  {% static_place all group 'some_group' %}

by default all statics are placed in the "default" group

work with static from php

you can connect and receive statics from your php code:

namespace App\Some;

use Skrip42\Bundle\StaticCollectorBunde\StaticCollector;

class SomeClass
{
    public function someMethod(StaticCollector $staticCollector)
    {
        //you can add some static to collector
        $staticCollector->addStatic('webpack_asset_or_external_link');
        //you can get style and script from staticCollector
        $staticCollector->getStyleTags();
        $staticCollector->getScriptTags();
        //you can remove all static from staticCollector
        $staticCollector->clear();
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固