briceburg/silverstripe-flexilink

使用单个灵活的 SilverStripe 字段链接到 SiteTree 页面、外部 URL、YouTube 视频等。

安装: 256

依赖项: 0

建议者: 1

安全: 0

星标: 5

关注者: 1

分支: 1

开放问题: 5

类型:silverstripe-module

0.1.0 2015-01-28 04:39 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:13:39 UTC


README

使用单个灵活的 SilverStripe 字段链接到 SiteTree 页面、外部 URL、YouTube 视频等。

需求

SilverStripe 3+

截图

flexichoice field

有关类似文本输入字段的更多信息,请参阅 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 提供以下公共模板方法
<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 以将其注册到清单中。