simonoche/white-label-bundle
最新稳定版本:v2.0.2
Composer 安装命令:
composer require simonoche/white-label-bundle
包简介
A simple White-Label Branding Bundle for Symfony2
README 文档
README
Warning - There is many changes between versions 1.0 and 2.0, Read the doc carefully before upgrading !
A basic & efficient White-Label Branding Bundle for Symfony2 (2.7+) that allows you to easily override twig templates (also with PHP templates) & twig globals.
This bundle is inspired by https://github.com/alexandresalome/multisite-bundle. Parts of which have been copyed and/or modified.
Requirements:
- FrameworkExtraBundle
- TwigBundle
Features
- Templates overriding per site
- Templates extending per site
- Specific configuration per site
- Globals overriding per site
- Load remote parts (header, footer), and cache them
- Declare multiple matching hosts (eg. one for development, one for production)
Installation
Download the bundle via composer
php composer.phar require simonoche/white-label-bundle
Simply load the bundle in you AppKernel.php
# app/AppKernel.php public function registerBundles() { $bundles = array( // your other bundles.... /* White Label Bundle */ new Slame\WhiteLabelBundle\SlameWhiteLabelBundle(), ); }
Configuration
Add this section to your app/config/config.yml file:
# app/config/config.yml slame_white_label: # Enable/Disable the bundle globally enabled: true # Your partner list partners: # Partner 1 partner1: # Enable or disable only this partner enable: true # Hosts to match hosts: [ 'mypartner.website.dev', 'mypartner.mysite.com' ] # Parts & Cache parts_cache: 86400 # (seconds) 1 day remote_parts: footer: "http://www.mypartner.com/?template_part=footer" header: "http://www.mypartner.com/?template_part=header" localfile: "%kernel.root_dir%/../web/static/partner/test-local.html" # The partner's namespace namespace: partner1 # Twig Global Overrides globals: phone: "08 00 00 00 00" # Partner's custom config, accessible via the service @site_context in templates or controllers locals: register: true foor: bar
Twig - Get remote parts
# AcmeDemoBundle::partner1/example_parts.html.twig {# Get the whole file #} {{ slame_getRemotePart('header')|raw }} {# Get a specific DOM node #} {{ slame_getRemotePart('header', 'body')|raw }} <div id="container"> {% block testblock %} bla bla {% endblock %} </div> {# Get the whole file #} {{ slame_getRemotePart('footer')|raw }}
Twig globals overriding
In each partner's section, you can define the twig globals that you want to be replaced, when the system find a matching partner.
Given your twig configuration is :
# app/config/config.yml twig: # ... globals: phone: 1234 name: %example_parameter% foo: bar gaid: ABCD-1234
If the visitor is browsing your partner's website (hostname) - so at http://partner1.mywebsite.com, the twig global will be automatically replaced by the value of you partner's globals (in this case, {{ phone }} will now display : "08 00 00 00 00")
You don't have to copy every "root" globals. Just the ones you want to be overrided automatically;
Twig templates overriding
If you want to change a template for a specific site, create a similarly named file with branding option in it:
Given your template is AcmeDemoBundle::contact.html.twig.
You can override it with branding by copying it in a subdirectory named by your partner's namespace:
AcmeDemoBundle::partner1/contact.html.twig
Just create the file and it will automatically be loaded in place of the previous one.
This method works with any kind of twig templates (layouts, includes, etc). For example, given your base template (general layout) is ::layout.html.twig (located in app/view/layout.html.twig).
You can easily override it with branding by copying it in a subdirectory named by your partner's namespace:
::partner1/layout.html.twig
Twig templates extending
If you just want to extend a template for a specific site, because you only need to override a few blocks, variables, or so.. Then just create a similarly named file with branding option in it:
Given your template is AcmeDemoBundle::test.html.twig.
You can override it with branding by copying it in a subdirectory named by your partner's namespace:
AcmeDemoBundle::partner1/test.html.twig
Just create the file and it will automatically be loaded in place of the previous one.
Then, you will need to extend the original template. So just extend the template, and don't forget to add a hashtag : # before your template file name. This hashtag indicates that you WANT to load the original file.
# AcmeDemoBundle::partner1/test.html.twig {# Force extending the original file #} {% extends "#AcmeDemoBundle::test.html.twig" %} {# Overriding only some blocks, etc... #} {% block sidebar %} {% set foo = bar %} Overriding the sidebar contents... {% endblock %} {% block body %} The partner's body, etc... {% endblock %}
Read the site context
From templates, use the global variable site_context, which returns a Slame\WhiteLabelBundle\Branding\SiteContext instance:
Get the whole partner's configuraton {{ site_context.getContext }}
You can also read options from config with: These options correspond to the "locals" section of your partner (in config.yml)
The option register is {{ site_context.option('register') ? 'enabled': 'not enabled' }}
In your controllers, use service site_context:
public function indexAction() { $this->get('site_context')->getOption('register'); }
Warning
Be carefull when playing with includes and extends, as you can be quickly stuck in a non-end loop, if you don't pay attention of what you do :) Read the section Twig templates extending if needed.
simonoche/white-label-bundle 适用场景与选型建议
simonoche/white-label-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.74k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「dimension」 「branding」 「cobrand」 「white-label」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 simonoche/white-label-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simonoche/white-label-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 simonoche/white-label-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
get image information without downloading whole file
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 5.74k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-19