brunschgi / terrific-core-bundle
支持基于 terrifc 概念的前端开发
Requires
- symfony/framework-bundle: 2.2.*
Requires (Dev)
- symfony/console: 2.2.*
- symfony/filesystem: 2.2.*
- symfony/finder: 2.2.*
- symfony/yaml: 2.2.*
- twig/twig: 1.12.x-dev
This package is not auto-updated.
Last update: 2024-09-28 16:16:53 UTC
README
TerrificCore 包使您能够轻松地根据 Terrific 概念 开发前端。它为您提供良好的起点和有用的功能(例如,额外的 assetic 过滤器),以简化您的前端开发。
TerrificCore 包没有依赖关系,但与 TerrificComposerBundle 一起使用效果最佳。有关安装 TerrificComposerBundle 的说明,请参阅此处。
安装
您可以通过 Composer 方便地安装 TerrificCoreBundle。只需将以下内容添加到您的 composer.json 文件中
// composer.json
{
// ...
require: {
// ...
"brunschgi/terrific-core-bundle": "dev-master"
}
}
注意:请将上面片段中的 dev-master 替换为最新的稳定分支,例如 1.0.*。请检查 Github 上的标签以确定哪些版本可用。然后,您可以从 composer.json 文件所在的目录运行 Composer 的 update 命令以安装新的依赖项
php composer.phar update
现在,Composer 将自动下载所有必需的文件,并为您安装它们。接下来需要做的就是更新您的 AppKernel.php 文件,并注册新的包
// in AppKernel::registerBundles()
public function registerBundles()
{
return array(
// ...
new Terrific\CoreBundle\TerrificCoreBundle(),
);
}
在 app/config/config.yml
中启用新的 terrificrewrite 过滤器
# app/config/config_dev.yml
# extend assetic filter configuration (rewrite of the backround image path in your terrific modules)
assetic:
…
filters:
…
terrificrewrite:
resource: %kernel.root_dir%/../vendor/brunschgi/terrific-core-bundle/Terrific/CoreBundle/Resources/config/terrificrewrite.xml
在 app/config/config_dev.yml
中启用包的配置
# app/config/config_dev.yml
terrific_core:
copy_images: true # copy your module images on the fly without running `assets:install web`
使用方法
要查看 TerrificComposerCore 的实际应用,请下载 Terrific Composer 分发版 并尝试使用包含的示例。有关 Terrific 概念的更多信息,请查看 http://terrifically.org
之后,以下内容应该相当简单 ;-)
基本布局
基本 twig 布局提供您开始 Terrific 项目所需的一切。只需从您的项目布局扩展基本布局即可
{# eg. src/Terrific/Composition/Resources/views/base.html.twig #} {% extends 'TerrificCoreBundle::base.html.twig' %} ...
核心布局提供您扩展或覆盖的几个 twig 块。其中最重要的包括
{# main content of your page #} {% block composition %}here comes the content of the <body> element…{% endblock %} {# content of the <title> element #} {% block title %}Terrific Composer{% endblock %} {# placeholder for your meta tags (charset is always set to utf-8) #} {% block meta %}here comes your meta tags…{% endblock %} {# styles #} {% block styles %} {% stylesheets '@TerrificComposition/Resources/public/css/reset.less' '@TerrificComposition/Resources/public/css/grid.less' '@TerrificComposition/Resources/public/css/elements.less' output="css/compiled/project.css" %} <link rel="stylesheet" href="{{ asset_url }}" /> {% endstylesheets %} {# styles from parent (terrific core) layout #} {{ parent() }} {% endblock %} {# scripts #} {% block scripts %} {% javascripts '../src/Terrific/Module/*/Resources/public/js/*.js' '../src/Terrific/Module/*/Resources/public/js/skin/*.js' output='js/compiled/base.js' %} <script src="{{ asset_url }}" type="text/javascript"></script> {% endjavascripts %} {% endblock %}
有关可用块的全列表,请参阅 @TerrificCoreBundle::base.html.twig。
模块宏
每个 Terrific 模块 都是一个单独的包。模块宏使得在页面上混合和匹配它们变得容易。它的工作方式类似于内置的 twig 辅助函数 include
和 render
,并将您包含/嵌入的模块模板包装在适当的模块 <div>
中,例如 <div class="mod mod-news" data-connectors="update">... your template ...</div>
。
包含模块模板
{# wrap & include the view template /src/Terrific/Module/Teaser/Resources/views/default.html.twig #}
{{ tc.module('Teaser', 'default') }}
{# wrap & include the view template /src/Terrific/Module/Teaser/Resources/views/Concept/reusability.html.twig #}
{{ tc.module('Teaser', 'Concept/reusability') }}
嵌入模块控制器
如果您正在使用 Terrific 构建不仅模板而且真正的应用程序,将所有数据相关的工作委托给模块本身可能很有用,这样您就不需要重复。
{# wrap & embed the module controller /src/Terrific/Module/Navigation/Controller/NavigationController.php -> mainAction #}
{{ tc.module('Navigation', 'Navigation:main') }}
模块宏可以接受比模块名称和视图更多的参数。
{% macro module(name, view, skins, connectors, attrs, data) %}
有关更详细的信息,请参阅 Twig/Extension/terrificcore.html.twig。
就是这样……享受吧!