briceburg / silverstripe-flexilink
使用单个灵活的 SilverStripe 字段链接到 SiteTree 页面、外部 URL、YouTube 视频等。
0.1.0
2015-01-28 04:39 UTC
Requires
- silverstripe/framework: ~3.0
Suggests
- briceburg/silverstripe-flexichoice: SilverStripe field for providing arbitrary text input or selecting from YAML configurable presets.
This package is not auto-updated.
Last update: 2024-09-14 16:13:39 UTC
README
使用单个灵活的 SilverStripe 字段链接到 SiteTree 页面、外部 URL、YouTube 视频等。
需求
SilverStripe 3+
截图
有关类似文本输入字段的更多信息,请参阅 silverstripe-flexichoice。
使用方法
- 将
FlexiLink
字段类型添加到您的DataObject
(s)
class BlockContentHeading extends DataObject { private static $db = array( 'Title' => 'Varchar', 'Content' => 'Text', 'Link' => 'FlexiLink', // <--- here 'LinkText' => 'FlexiChoice', );
在扩展对象后触发环境构建器 (/dev/build) -- 现在,当您编辑对象时,您将在 CMS 中看到 FlexiLinkField
出现。
FlexiLink
提供以下公共模板方法- 类型 : 链接类型(例如,'ExternalURL'、'Page'、'YouTubeID')
- 值 : 链接的原始值
- URL : 将链接转换为 URL(例如,Page->Link(),'http://www.google.com/','//www.youtube.com/embed/[Value]')
<div class="block-heading"> <h1>$Title</h1> $Content <% if Link.exists %> <div class="link"> <% if Link.Type == 'YouTubeID' %> <a class="button" href="$Link.URL" target="_blank">WATCH <span>MOVIE</span></a> <% else %> <a class="button" href="$Link.URL">$LinkText</a> <% end_if %> </div> <% end_if %> </div>
- 您可以在 YAML 配置 中定义链接选择类型及其相关字段。以下是一个示例 /mysite/config/_config.yml
--- Name: mysite After: - 'framework/*' - 'cms/*' --- # YAML configuration for SilverStripe # See http://doc.silverstripe.org/framework/en/topics/configuration # Caution: Indentation through two spaces, not tabs SSViewer: theme: 'site' FlexiLinkField: allowed_types: - Page - Google field_types: Google: field: TextField description: TestTest
此示例添加了一个自定义的 'Google' 字段类型,并将下拉选择限制为 'Page' 和 'Google'(隐藏内置的 YouTubeID 和 ExternalURL)。
注意,在 YML 配置更改后,请使用 ?flush=all 以将其注册到清单中。