fromholdio/silverstripe-dbhtmlanchors 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fromholdio/silverstripe-dbhtmlanchors

最新稳定版本:2.1.0

Composer 安装命令:

composer require fromholdio/silverstripe-dbhtmlanchors

包简介

Quick and easy method of identifying anchors in DBHTMLText and DBHTMLVarchar fields

README 文档

README

Quick and easy method of identifying anchors in DBHTMLText and DBHTMLVarchar fields.

Requirements

SilverStripe 4

Installation

composer require fromholdio/silverstripe-dbhtmlanchors

Detail

Upon install, the DBHTMLAnchorsExtension is automatically applied to DBHTMLText and DBHTMLVarchar.

This adds a getAnchors() accessor to each of these DBFields.

When called on the field object, it processes any shortcodes, and then searches the html elements for name and id attributes that can be used as anchor link targets.

The list of anchor values is returned as a simple array.

Usage example

Add a DBHTMLText or DBHTMLVarchar to your data object. The Content field of SiteTree is a common example of one that already exists.

private static $db = [
    'Content' => 'HTMLText'
];

In your code, get the field object, and call getAnchors(). Make sure you get the field object, not the field's value.

// CORRECT
$contentField = $this->dbObject('Content');
$anchors = $contentField->getAnchors();

// WRONG
$contentField = $this->Content;
$anchors = $contentField->getAnchors();

The value returned will be either null for no results, or an associative array, with key and value both containing the anchor value.

// return value from ->getAnchors()
[
    'sectionone' => 'sectionone',
    'sectiontwo' => 'sectiontwo'
]

统计信息

  • 总下载量: 1.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-02-17