定制 symfony/ux-swup 二次开发

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

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

symfony/ux-swup

最新稳定版本:v2.31.0

Composer 安装命令:

composer require symfony/ux-swup

包简介

Swup integration for Symfony

关键字:

README 文档

README

Warning

Deprecated: This package has been deprecated in 2.x and will be removed in the next major version.

To keep the same functionality in your Symfony application, follow these migration steps:

  1. Install the swup library and its plugins:
# If using Symfony AssetMapper:
php bin/console importmap:require swup @swup/fade-theme @swup/slide-theme @swup/forms-plugin @swup/debug-plugin

# If using NPM (e.g.: with Webpack Encore):
npm install swup @swup/fade-theme @swup/slide-theme @swup/forms-plugin @swup/debug-plugin
  1. Add the following code to your app:
assets/controllers/swup_controller.js
import { Controller } from '@hotwired/stimulus';
import Swup from 'swup';
import SwupFadeTheme from '@swup/fade-theme';
import SwupSlideTheme from '@swup/slide-theme';
import SwupFormsPlugin from '@swup/forms-plugin';
import SwupDebugPlugin from '@swup/debug-plugin';

export default class extends Controller {
    static values = {
        containers: Array,
        mainElement: String,
        animateHistoryBrowsing: Boolean,
        animationSelector: String,
        cache: Boolean,
        linkSelector: String,
        theme: String,
        debug: Boolean,
    };

    connect() {
        const dataContainers = this.containersValue;
        const mainElement = this.mainElementValue || dataContainers[0] || '#swup';
        const allElements = [mainElement].concat(dataContainers);
        const containersList = allElements.filter((item, index) => {
            return allElements.indexOf(item) === index;
        });

        const options = {
            containers: containersList,
            plugins: [
                'slide' === this.themeValue
                    ? new SwupSlideTheme({ mainElement: mainElement })
                    : new SwupFadeTheme({ mainElement: mainElement }),
                new SwupFormsPlugin(),
            ],
        };

        if (this.hasMainElementValue) {
            options.mainElement = this.mainElementValue;
        }

        if (this.hasAnimateHistoryBrowsingValue) {
            options.animateHistoryBrowsing = this.animateHistoryBrowsingValue;
        }
        if (this.hasAnimationSelectorValue) {
            options.animationSelector = this.animationSelectorValue;
        }
        if (this.hasCacheValue) {
            options.cache = this.cacheValue;
        }
        if (this.hasLinkSelectorValue) {
            options.linkSelector = this.linkSelectorValue;
        }
        if (this.debugValue) {
            options.plugins.push(new SwupDebugPlugin());
        }

        this.dispatchEvent('pre-connect', { options });
        const swup = new Swup(options);
        this.dispatchEvent('connect', { swup, options });
    }

    dispatchEvent(name, payload) {
        this.dispatch(name, { detail: payload, prefix: 'swup' });
    }
}
  1. Replace the symfony--ux-swup occurrences in your templates with swup, for example:
-<body {{ stimulus_controller('symfony/ux-swup/swup') }}>
+<body {{ stimulus_controller('swup') }}>
  1. Remove symfony/ux-swup from your dependencies:
composer remove symfony/ux-swup

You're done!

Symfony UX Swup is a Symfony bundle integrating Swup in Symfony applications. It is part of the Symfony UX initiative.

Swup is a complete and easy to use page transition library for Web applications. It creates a Single Page Application feel to Web applications without having to change anything on the server and without bringing the complexity of a React/Vue/Angular application.

This repository is a READ-ONLY sub-tree split. See https://github.com/symfony/ux to create issues or submit pull requests.

Sponsor

The Symfony UX packages are backed by Mercure.rocks.

Create real-time experiences in minutes! Mercure.rocks provides a realtime API service that is tightly integrated with Symfony: create UIs that update in live with UX Turbo, send notifications with the Notifier component, expose async APIs with API Platform and create low level stuffs with the Mercure component. We maintain and scale the complex infrastructure for you!

Help Symfony by sponsoring its development!

Resources

统计信息

  • 总下载量: 141.76k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 33
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 33
  • Watchers: 7
  • Forks: 3
  • 开发语言: TypeScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固