All Projects → ryanshrum → Hacksaw

ryanshrum / Hacksaw

Licence: mit
A simple text truncation plugin for Craft CMS.

Labels

Projects that are alternatives of or similar to Hacksaw

Awesome
A collection of awesome Craft CMS plugins, articles, resources and shiny things.
Stars: ✭ 449 (+1182.86%)
Mutual labels:  craftcms
Craft Emptycoalesce
Empty Coalesce adds the ??? operator to Twig that will return the first thing that is defined, not null, and not empty
Stars: ✭ 24 (-31.43%)
Mutual labels:  craftcms
Craft3 Iconpicker
Craft plugin that provides a new field type that offers end users an easy way to pick an icon from a .woff or .ttf font file. You can easily use ionicons or font awesome icons or any other compatible font file.
Stars: ✭ 15 (-57.14%)
Mutual labels:  craftcms
Demo
“Happy Lager” Craft CMS demo site.
Stars: ✭ 730 (+1985.71%)
Mutual labels:  craftcms
Craft Lettering
Lettering.js ported to Craft
Stars: ✭ 19 (-45.71%)
Mutual labels:  craftcms
Commercemailer
ARCHIVED: For Craft Commerce. Makes it easy to create forms for sending carts, products and orders by email.
Stars: ✭ 8 (-77.14%)
Mutual labels:  craftcms
Seomatic
DEPRECATED A turnkey SEO implementation for Craft CMS 2.x that is comprehensive, powerful, and flexible
Stars: ✭ 366 (+945.71%)
Mutual labels:  craftcms
Craft Fieldguide
A simple Craft CMS plugin that lists all your fields and their handles, grouped by section
Stars: ✭ 33 (-5.71%)
Mutual labels:  craftcms
Plugin Installer
Composer installer for Craft CMS plugins
Stars: ✭ 22 (-37.14%)
Mutual labels:  craftcms
Vanillaforums
DEPRECATED Single Sign On plugin for VanillaForums/jsConnect and CraftCMS
Stars: ✭ 14 (-60%)
Mutual labels:  craftcms
Craft Bugsnag
Log Craft errors/exceptions to Bugsnag.
Stars: ✭ 6 (-82.86%)
Mutual labels:  craftcms
Geomate
GeoMate is a friend in need for all things geolocation. IP to geo lookup, automatic redirects (based on country, continent, language, etc), site switcher... You name it.
Stars: ✭ 19 (-45.71%)
Mutual labels:  craftcms
Snipcart Craft Webhooks Plugin
Sample plugin to allow inventory management in a Craft application using Snipcart
Stars: ✭ 11 (-68.57%)
Mutual labels:  craftcms
Element Api
Create a JSON API/Feed for your elements in Craft.
Stars: ✭ 493 (+1308.57%)
Mutual labels:  craftcms
Craft Coordinates
A twig filter for Craft CMS that gets the latitude and longitude from an address
Stars: ✭ 27 (-22.86%)
Mutual labels:  craftcms
Craft Neo
A Matrix-like field type for Craft CMS that uses existing fields
Stars: ✭ 387 (+1005.71%)
Mutual labels:  craftcms
Craft Do Forge Recipe
Digital Ocean / Forge Recipe for CraftCMS websites
Stars: ✭ 24 (-31.43%)
Mutual labels:  craftcms
Commerceregisteroncheckout
ARCHIVED: SEE README Allow user registration during Craft Commerce V1 checkouts.
Stars: ✭ 34 (-2.86%)
Mutual labels:  craftcms
Craft Twofactorauthentication
Craft plugin for two-factor or two-step login using Time Based OTP.
Stars: ✭ 31 (-11.43%)
Mutual labels:  craftcms
Falcon
Enables Xkey / Hash-Two / Surrogate Key caching with Craft 2.x. Very experimental.
Stars: ✭ 14 (-60%)
Mutual labels:  craftcms

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).

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


Hacksaw for Craft CMS

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

Installation

To install Hacksaw, follow these steps:

  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:

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.

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:

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

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

{{ 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:

Note: <p>'s are automatically allowed when hacking by paragraph.

{{ 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:

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

Brought to you by Ryan Shrum

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].