All Projects → craftcms → anchors

craftcms / anchors

Licence: MIT license
Add anchor links to headings in your Craft CMS website content.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to anchors

query
Run SQL queries as an admin from the Craft CMS control panel.
Stars: ✭ 14 (-70.21%)
Mutual labels:  yii2, craftcms, craft-plugin, craft3, craft2
craft-router
A Craft CMS plugin for using URL segments as filtering criteria on an entry query.
Stars: ✭ 21 (-55.32%)
Mutual labels:  craftcms, craft-plugin, craft3, craft2
store-hours
Manage business hours with Craft CMS.
Stars: ✭ 60 (+27.66%)
Mutual labels:  craftcms, craft-plugin, craft3, craft2
craft3-forms
This craft CMS 3 form plugin makes it easy to create and use custom forms with the features the Yii 2 Framework offers. On top of this, the plugin provides even more functionalities for easy implementation of forms in twig templates.
Stars: ✭ 20 (-57.45%)
Mutual labels:  craftcms, craft-plugin, craft3
PowerNap
Sample Task plugin
Stars: ✭ 15 (-68.09%)
Mutual labels:  craftcms, craft-plugin, craft2
Cms
Craft is a flexible, user-friendly CMS for creating custom digital experiences on the web and beyond.
Stars: ✭ 2,713 (+5672.34%)
Mutual labels:  yii2, craftcms, craft3
craft-react
Client and Server-side React rendering for CraftCMS
Stars: ✭ 40 (-14.89%)
Mutual labels:  craftcms, craft-plugin, craft3
craft-typogrify
Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more
Stars: ✭ 70 (+48.94%)
Mutual labels:  craftcms, craft-plugin, craft3
tablemaker
A user-definable table field type for Craft CMS
Stars: ✭ 39 (-17.02%)
Mutual labels:  craftcms, craft-plugin, craft3
like
Let your users like your Craft website's entries, assets and any other element.
Stars: ✭ 44 (-6.38%)
Mutual labels:  craftcms, craft-plugin, craft2
craft-audit
Audit log for Craft 3
Stars: ✭ 18 (-61.7%)
Mutual labels:  craftcms, craft-plugin, craft3
DigitalProducts
Sell digital products with Craft Commerce
Stars: ✭ 48 (+2.13%)
Mutual labels:  craftcms, craft-plugin, craft2
Craft
Composer starter project for Craft CMS
Stars: ✭ 122 (+159.57%)
Mutual labels:  yii2, craftcms, craft3
Spoon
Spoon plugin for Craft CMS - Enhance your Matrix fields with groups, tabs and more!
Stars: ✭ 82 (+74.47%)
Mutual labels:  craftcms, craft-plugin, craft3
Inlin-Craft
Plugin for inlining files in templates.
Stars: ✭ 64 (+36.17%)
Mutual labels:  craftcms, craft3, craft2
Craft Imageoptimize
Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.
Stars: ✭ 227 (+382.98%)
Mutual labels:  craftcms, craft-plugin, craft3
Commerce
Fully integrated ecommerce for Craft CMS
Stars: ✭ 144 (+206.38%)
Mutual labels:  craftcms, craft-plugin, craft3
Seo
SEO utilities including a unique field type, sitemap & redirect manager
Stars: ✭ 210 (+346.81%)
Mutual labels:  craftcms, craft-plugin, craft3
AssetSubfolderAccess
Limits user groups to only access certain asset subfolders
Stars: ✭ 18 (-61.7%)
Mutual labels:  craftcms, craft-plugin, craft2
craft-cookies
A simple plugin for setting and getting cookies from within Craft CMS templates.
Stars: ✭ 36 (-23.4%)
Mutual labels:  craftcms, craft-plugin, craft3

Anchors for Craft CMS

This plugin makes it possible to automatically add linkable anchors to HTML headings in Craft.

The anchors are named based on the heading text. The algorithm Anchors uses to convert the heading text to IDs is similar to Craft’s algorithm for automatically generating entry slugs.

Requirements

This plugin requires Craft CMS 4.0 or later.

Installation

You can install this plugin from the Plugin Store or with Composer.

From the Plugin Store

Go to the Plugin Store in your project’s Control Panel and search for “Anchors”. Then click on the “Install” button in its modal window.

With Composer

Open your terminal and run the following commands:

# go to the project directory
cd /path/to/my-project.test

# tell Composer to load the plugin
composer require craftcms/anchors

# tell Craft to install the plugin
./craft install/plugin anchors

Templating

To use Anchors in your templates, just pass some HTML into the |anchors filter.

{{ entry.body|anchors }}

By default, the anchors filter will only search for <h1>, <h2>, and <h3> tags. You can customize which tags it searches for by passing in a comma-separated list of tag names.

{{ entry.body|anchors('h2,h3') }}

The anchors filter will convert any non-ASCII characters to ASCII, using the current site’s language’s ASCII character mappings by default.

If you are displaying content in a different language than the current site, use the language argument to override which ASCII character mappings should be used:

{{ entry.body|anchors(language=entry.site.language) }}

Configuration

To configure Anchors, create a new anchors.php file within the config/ folder, which returns an array.

The following config settings are supported:

  • anchorClass – The class name that should be given to named anchors. (Default is null, meaning no class will be given.)
  • anchorLinkPosition – The position that anchor links should have within headings, relative to the heading text ('before' or 'after'). (Default is 'after'.)
  • anchorLinkClass – The class name that should be given to anchor links. (Default is 'anchor'.)
  • anchorLinkText – The visible text that anchor links should have. (Default is '#''.)
  • anchorLinkTitleText – The title/alt text that anchor links should have. If {heading} is included, it will be replaced with the heading text the link is associated with. (Default is 'Direct link to {heading}'.)

Plugin API

Other plugins can take advantage of Anchors using the provided API.

$parsedHtml = \craft\anchors\Plugin::getInstance()->parser->parseHtml($html);

Like the |anchors templating filter, parseHtml() also allows you to specify which HTML tags should get anchors.

$parsedHtml = \craft\anchors\Plugin::getInstance()->parser->parseHtml($html, 'h2,h3');

You can also pass some heading text directly into Anchors to get its generated anchor name:

$anchorName = \craft\anchors\Plugin::getInstance()->parser->generateAnchorName($headingText);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].