codingfogey / fontawesome-bundle
Requires
- php: >=5.3.3
- symfony/symfony: >=2.3
Requires (Dev)
- phpunit/phpunit: 3.7.*
Suggests
- braincrafted/bootstrap-bundle: BraincraftedBootstrapBundle integrates Bootstrap into Symfony2 by providing templates, Twig extensions, services and commands.
- fortawesome/font-awesome: The iconic font designed for Bootstrap
- twbs/bootstrap: Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
This package is not auto-updated.
Last update: 2022-02-01 12:28:29 UTC
README
由于 braincrafted/bootstrap-bundle 现在直接支持 Font Awesome,因此此包不再维护。
CodingfogeyFontAwesomeBundle
关于
此 Bundle 使您能够轻松将 Font Awesome 集成到您的 Symfony2 项目中。
先决条件
安装
-
将
codingfogey/fontawesome-bundle添加到您的composer.json{ ... "require": { ... "codingfogey/fontawesome-bundle": "dev-master", "fortawesome/font-awesome": "v4.0.3" } ... } -
将
CodingfogeyFontAwesomeBundle添加到您的AppKernel.php... public function registerBundles() { $bundles = array( ... new Codingfogey\Bundle\FontAwesomeBundle\CodingfogeyFontAwesomeBundle() ); ... } ... -
更新您的依赖项:
composer update。
注意:通过 composer 安装 Font Awesome 是可选的,但可以使此包立即工作。因此,我建议这种方式。
配置
如果您没有通过 composer 安装 Font Awesome,您需要配置到您的安装路径
codingfogey_font_awesome:
assets_dir: %kernel.root_dir%/../vendor/fortawesome/font-awesome
定制
如果您想定制 Font Awesome,您必须在您的项目中某处放置一个定制的变量文件,并配置路径。您还需要设置输出路径。
codingfogey_font_awesome:
filter: less
customize:
variables_file: %kernel.root_dir%/Resources/fontawesome/variables.less
font_awesome_output: %kernel.root_dir%/Resources/less/fontawesome.less
如果您想使用 lessphp 或 sass Assetic 过滤器,您必须相应地设置 filter 变量。
有一个命令可以生成一个定制的输出文件,以包含您的定制变量文件
app/console codingfogey:fontawesome:generate
用法
字体文件的安装
此包提供了一个命令,用于将字体文件安装到 web/fonts 目录
app/console codingfogey:fontawesome:install
还有一个 ScriptHandler,可以在每次 composer install 或 composer update 时方便地自动执行此操作
...
"scripts": {
"post-install-cmd": [
...
"Codingfogey\\Bundle\\FontAwesomeBundle\\Composer\\ScriptHandler::install"
],
"post-update-cmd": [
...
"Codingfogey\\Bundle\\FontAwesomeBundle\\Composer\\ScriptHandler::install"
]
},
...
要包含 Font Awesome CSS,只需在您的基模板中包含 @fontawesome_css 即可。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}
{% stylesheets
'@fontawesome_css'
%}
<link rel="stylesheet" href="{{ asset_url }}" media="screen"/>
{% endstylesheets %}
{% endblock %}
添加图标
您可以按照 这里 的描述添加图标。
您还可以使用方便的 Twig 函数。
注意:如果您修改了@fa-css-prefix变量,则此功能将无法正常工作。
简单图标
要插入简单图标,请将{{ fa_icon( icon name|options ) }}添加到您的模板中。
参数可以是只包含图标名称(不含fa-前缀)的string,或者更复杂定制的JSON。完整的选项列表如下
{
icon: name of the icon without 'fa-' prefix
scale: [lg|2x|3x|4x|5x|stack-1x|stack-2x],
fixed-width: [true|false],
list-icon: [true|false],
border: [true|false],
pull: [left|right],
spin: [true|false],
rotate: [90|180|270],
flip: [horizontal|vertical],
inverse: [true|false]
}
堆叠图标
要插入堆叠图标,请将{{ fa_icon( options, options [, container] ) }}添加到您的模板中。第一个参数用于前景图标,第二个参数用于背景图标。这些参数必须是JSON,因为每个图标至少需要提供两个参数:图标名称和缩放比例。
最后一个参数是可选的,可以包含容器元素的选项。完整的容器选项列表如下
{
type: html element type for the container (default: span)
scale: [lg|2x|3x|4x|5x]
}
待办事项
请查看这里。
许可证
致谢
- 此软件包主要受到braincrafted/bootstrap-bundle的启发,大部分代码都是从那里取用的。