2017 © Pedro PelĂĄez
 

craft-plugin hacksaw

A simple text truncation plugin for Craft CMS.

image

ryanshrum/hacksaw

A simple text truncation plugin for Craft CMS.

  • Tuesday, April 17, 2018
  • by ryanshrum
  • Repository
  • 3 Watchers
  • 35 Stars
  • 1,544 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

Notice (4/17/2018):

Unfortunately, due to not working with Craft anymore and a lack of time, I haven’t been able to get Hacksaw updated for Craft 3. I would recommend NY Studio's Tyopgrify or Top Shelf Craft’s Wordsmith (which includes native backwards compatibility for Hacksaw)., (*1)

Additionally, if you would like to takeover as the maintainer of Hacksaw, please let me know and I will handover the reins., (*2)


Hacksaw for Craft CMS

A simple text truncation plugin for Craft CMS that takes your content and hacks it down to more manageable sizes., (*3)

Installation

To install Hacksaw, follow these steps:, (*4)

  1. Download & unzip the file and place the hacksaw directory into your craft/plugins directory
    -OR-
    Do a git clone https://github.com/ryanshrum/hacksaw.git directly into your craft/plugins folder. You can then update it with git pull
    -OR-
    Install with Composer via composer require ryanshrum/hacksaw
  2. Install plugin in the Craft Control Panel under Settings > Plugins
  3. The plugin folder should be named hacksaw for Craft to see it. GitHub recently started appending -master (the branch name) to the name of the folder for zip file downloads.

Usage

Hacksaw is a Twig filter that accepts the following parameters:, (*5)

Parameter Type Default Description
hack string 'p' What you want to hack on ('characters', 'words' or 'paragraphs' - can also use first letter as short hand 'c', 'w' or 'p')
limit int 1 Starting point for chars limit (used with chars param)
allow string null Sometimes there are HTML tags in your content that you don' removed, pass them here
append string null String to append to the end of the excerpt

Note: Cutoff has been deprecated from Hackasw., (*6)

Examples

Hacking by paragraphs is default, so if you wanted to limit your text to 5 paragraphs, you would only need to set the limit parameter:, (*7)

{{ entry.richTextField|hacksaw(limit='5') }}

If you wanted to limit to 50 characters or words, you'd use both the hack and limit parameter:, (*8)

{{ entry.richTextField|hacksaw(hack='characters', limit='50') }}
{{ entry.richTextField|hacksaw(hack='words', limit='50') }}

Hacksaw will strip all HTML from your excerpt by default. If you would like to keep some basic HTML you can use the allow parameter to keep specific HTML tags. For example, let's say you want to keep <a> and <b> tags:, (*9)

Note: <p>'s are automatically allowed when hacking by paragraph., (*10)

{{ entry.richTextField|hacksaw(limit='10', allow='<a><b>') }}

Note: If you are including HTML in the append parameter, the elements must be present in the allow parameter. If you are including a Craft variable in any parameter, it must be added using the Twig concatenation operator, ~. Example of both:, (*11)

{{ entry.richTextField|hacksaw(hack='w', limit='100', allow='<a>', append='<a href="' ~ entry.url ~ '">Continue...</a>') }}

Brought to you by Ryan Shrum, (*12)

The Versions

17/04 2018

dev-master

9999999-dev

A simple text truncation plugin for Craft CMS.

  Sources   Download

The Requires

 

26/06 2017

2.0.1

2.0.1.0

A simple text truncation plugin for Craft CMS.

  Sources   Download

The Requires

 

13/09 2016

2.0.0

2.0.0.0

A simple text truncation plugin for Craft CMS.

  Sources   Download

The Requires