2017 © Pedro Peláez
 

craft-plugin linkit

Link fieldtype for Craft

image

itmundi/linkit

Link fieldtype for Craft

  • Monday, November 9, 2015
  • by nerds-and-company
  • Repository
  • 2 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 33 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Linkit plugin for Craft

One link field to replace them all, a multi-purpose link fieldtype for Craft CMS., (*1)

This plugin adds a fieldtype which links to all sorts of stuff, Linkit can currently link to:, (*2)

  • Entries
  • Assets
  • Categories
  • Emails
  • Phone numbers
  • Custom URLs

And it plays really nicely with Matrix!, (*3)

Field settings allow you to:, (*4)

  • Configure what elements each field can link too.
  • Set which entry/asset sources are available to each field.
  • Allow fields to set custom link text.
  • Allow fields to set links to open in new window.
  • Set default link text.

Installation

To install Linkit, follow these steps:, (*5)

  1. Upload the linkit/ folder to your craft/plugins/ folder.
  2. Go to Settings > Plugins from your Craft control panel and enable the Linkit plugin.
  3. Create and configure a new linkit field.

Template Usage

Get the link object:, (*6)

{% set yourLink = entry.yourLinkFieldHandle %}

Just the link - output a pre built HTML link:, (*7)

{{ yourLink.link|raw }}

Build a simple custom link:, (*8)

<a href="{{ yourLink.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">{{ yourLink.linkText }}</a>

Build your own:, (*9)

{% switch yourLink.type %}

    {% case "entry" %}

        <a href="{{ yourLink.entry.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.entry.title }}">{{ yourLink.entry.title }}</a>

    {% case "category" %}

        <a href="{{ yourLink.category.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.category.title }}">{{ yourLink.category.title }}</a>

    {% case "asset" %}

        <a href="{{ yourLink.asset.url }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.asset.title }}">
            {% if yourLink.asset.kind == 'image' %}
                <img src="{{ yourLink.asset.url('thumb') }}" />
            {% else %}
                <img src="thumb-{{ yourLink.asset.kind }}.png" />
            {% endif %}
        </a>        

    {% case "custom" %}

        <a href="{{ yourLink.custom }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">
            <i class="custom-link-icon"></i> {{ yourLink.linkText }}
        </a>

    {% case "email" %}

        <a href="mailto:{{ yourLink.email }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">{{ yourLink.email }}</a></p>

    {% case "tel" %}

        <a href="tel:{{ yourLink.tel }}" {{ yourLink.target ? ' target="_blank"' }} title="{{ yourLink.linkText }}">{{ yourLink.tel }}</a></p>

{% endswitch %}

Template Variables

Each link returns a link object which contains the following:, (*10)

{% set yourLink = entry.yourLinkFieldHandle %} // Get the link

{{ yourLink.type }} // Returns the link type - entry, asset, email, tel, custom

{{ yourLink.email }}    // Email String / False
{{ yourLink.custom }}   // Custom URL String / False
{{ yourLink.tel }}      // Telephone Number / False
{{ yourLink.entry }}    // Entry Object / False
{{ yourLink.category }} // Category Object / False
{{ yourLink.asset }}    // Asset Object / False
// Each link type is returned - only the active type will return data the rest return false

{{ yourLink.text }}     // The Custom Text String 
{{ yourLink.target }}   // True/False (Bool) - Open in new window? 

{{ yourLink.url }}      // The full url (correct prefix added eg mailto: or tel:)
{{ yourLink.linkText }} // The link text string ready to use (If no custom text is provided it generates it based on the link type)

{{ yourLink.link }}     // Full link HTML ready to use  

Roadmap

  • Force download option
  • Rework the way link data is returned
  • Improve handling of target stuff - if it's required
  • More Validation Options

Changelog

0.9.1

  • Fixed: Input field not displaying correctly when set to single type when field had previously been saved.
  • Fixed: Custom text returning false.

0.9

  • Added: Removed the requirement to use the |raw filter when using the link variable.
  • Fixed: Input field now corectly displays when on one link type is setup.

0.8.1

  • Added: Hide the Link To... select when only one link type has been selected for the field.

0.8

  • Added: Category Support

0.7

  • Added: Default Text - Fieldtype setting to add default link text for a link.

0.6

  • Fix: PHP Error when returning an entry or asset that has subsequently been deleted

0.5

  • Initial beta release

Licence

Copyright 2014 Fruit Studios Ltd, (*11)

The Versions

09/11 2015

dev-master

9999999-dev

Link fieldtype for Craft

  Sources   Download

MIT

The Requires

 

16/10 2015

dev-feature/composer-compatibility

dev-feature/composer-compatibility

Link fieldtype for Craft

  Sources   Download

MIT

The Requires