silverstripe-modular-project / silverstripe-links
该包已废弃,不再维护。作者建议使用 gorriecoe/silverstripe-link 包。
dev-master
2017-07-24 02:19 UTC
Requires
- php: >=5.3.2
- silverstripe/framework: ^3.5
- unclecheese/display-logic: ^1.4
This package is not auto-updated.
Last update: 2019-05-30 21:43:49 UTC
README
添加一个可以链接到URL、电子邮件、电话号码、内部页面或文件的链接对象。
安装
Composer是安装SilverStripe模块的推荐方式。
composer require silverstripe-modular-project/silverstripe-links
需求
- silverstripe/framework 3.5.*
- unclecheese/display-logic 1.4.*
维护者
冲突
此模块与 Linkable 存在直接冲突。
示例用法
class Page extends SiteTree { private static $has_one = array( 'ExampleLink' => 'Link' ); public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab( 'Root.Link', LinkField::create( 'ExampleLinkID', 'Link to page or file' ) ); return $fields; } }
在模板中,您可以使用以下方式渲染链接锚点标签
{$ExampleLink}
模板选项
基本用法
<!-- has one relationship --> {$ExampleLink} <!-- many relationship --> <% loop ExampleLinks %> {$Me} <% end_loop %>
定义链接类
<!-- has one relationship --> {$ExampleLink.setCSSClass(button)} <!-- many relationship --> <% loop ExampleLinks %> {$setCSSClass(button)} <% end_loop %>
定义一个自定义模板来渲染链接
<!-- has one relationship --> {$ExampleLink.renderWith(Link_button)} <!-- many relationship --> <% loop ExampleLinks %> {$renderWith(Link_button)} <% end_loop %>
定义一个自定义样式。这将应用一个CSS类,并如果存在,则渲染一个自定义模板。以下示例将在includes目录中查找Link_button.ss。
<!-- has one relationship --> {$ExampleLink.setStyle(button)} <!-- many relationship --> <% loop ExampleLinks %> {$setStyle(button)} <% end_loop %>
自定义模板
<% with ExampleLink %> <% if LinkURL %> <a href="{$LinkURL}"{$TargetAttr}{$ClassAttr}> {$Title} </a> <% end_if %> <% end_with %>
CMS可选样式
您可以为CMS用户提供从样式列表中选择的能力,让他们选择如何渲染他们的链接。要启用此功能,请在您的site config.yml文件中按以下方式注册它们。
Link: styles: button: Description of button template # applies button class and looks for Link_button.ss template iconbutton: Description of iconbutton template # applies iconbutton class and looks for Link_iconbutton.ss template
限制允许的链接类型
全局限制链接类型。要限制类型,请定义它们在您的site config.yml文件中,如下所示。
Link: allowed_types: - URL - SiteTree
要为每个字段本地限制链接类型。请注意,定义本地类型不会继承全局设置,而是覆盖它。
LinkField::create( 'ExampleLinkID', 'Link Title' ) ->setAllowedTypes('URL','Phone')