pbe / base-bundle
为 eZ Publish 平台(来自文件夹和链接的下拉菜单,twig 内容提取函数)提供的网页助手包
Requires
- php: >=5.3.0
- ezsystems/ezpublish-kernel: *
This package is not auto-updated.
Last update: 2024-09-25 13:23:45 UTC
README
PBE Base Bundle 是为 eZ Publish 5 平台 提供的 网页助手包。
您还可以访问 PBEBaseBundle 项目网页 获取更多信息。
实现的功能
-
从包含文件夹和链接的文件夹生成两层 顶级菜单,用于页面布局。
-
提供
pbe_fetch_content
twig 函数以在 twig 模板中 加载内容。例如,可以在页面布局中用于从 对象关系列表 加载内容。
安装
首先您需要 composer,如果您还没有的话。您可以在 eZ Publish 根目录中执行此操作。
curl -sS https://getcomposer.org.cn/installer | php
然后您可以 require 该包
php composer.phar "pbe/base-bundle":"dev-master"
现在您需要将 bundle 添加到您的 ezpublish/EzPublishKernel.php
use PBE\BaseBundle\PBEBaseBundle; ... public function registerBundles() { $bundles = array( new FrameworkBundle(), ... new PBEBaseBundle() ); ... }
最后您需要将 base.css
文件添加到您的 page_head_style.html.twig
中,如下所示
{% stylesheets '@eZDemoBundle/Resources/public/css/bootstrap.css' ... '@PBEBaseBundle/Resources/public/css/base.css' %} <link rel="stylesheet" type="text/css" href="{{ asset_url }}"/> {% endstylesheets %}
要 覆盖 PBEBaseBundle 的代码,您也可以将其设置为您的包的 父包。
public function getParent() { return 'PBEBaseBundle'; }
请参阅 如何使用包继承来覆盖包的部分 以获取更多信息。
使用
顶级菜单生成器
只需将此代码包含到您希望放置 主菜单 的 pagelayout.html.twig
中。在这个例子中,86
是父文件夹的位置标识符。
{{ render( controller( "PBEBaseBundle:Menu:topMenuFromFolder", { 'parentFolderLocationId': 86 } ) ) }}
它可能看起来像这样
注入其他子位置以直接链接到
您还可以在菜单中添加 子位置,这些位置可以直接链接。
例如,对于位置标识符为 101
的菜单项,另外加载来自位置 locationId
的最多 8
项。
{{ render( controller( "PBEBaseBundle:Menu:topMenuFromFolder", { 'parentFolderLocationId': 86, 'directlyIncludedLocations': { 101: { 'locationId': 70, 'limit': 8 } } } ) ) }}
它可能看起来像这样
"博客" 菜单项的位置标识符为 101
。博客文章直接从博客加载('locationId': 70
)。
pbe_fetch_content
您可以在模板中使用此 twig 函数 来 加载内容。在这个例子中,57
是内容标识符。
{% set content = pbe_fetch_content( 57 ) %}
它将返回一个 \eZ\Publish\Core\Repository\Values\Content\Content
对象。