2017 © Pedro Peláez
 

craft-plugin craft-cta-field

Call to action & link fields made easy

image

statikbe/craft-cta-field

Call to action & link fields made easy

  • Thursday, July 26, 2018
  • by statikbe
  • Repository
  • 7 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

CTA field plugin for Craft

Requirements

This plugin requires Craft CMS 3.0.0 or later., (*1)

Installation

To install the plugin, follow these instructions., (*2)

  1. Open your terminal and go to your Craft project:, (*3)

    cd /path/to/project
  2. Then tell Composer to load the plugin:, (*4)

    composer require statikbe/craft-cta-field
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Link Field., (*5)

Templating

Link fields on your models will return an instance of cta\models\Link. Rendering a link field directly within a template will return the url the field is pointing to., (*6)

<a href="{{ item.myLinkField }}">Link</a>

You can use the following accessors to get the different properties of the link:, (*7)

{{ item.myLinkField.getElement() }}
{{ item.myLinkField.getTarget() }}
{{ item.myLinkField.getText() }}
{{ item.myLinkField.getUrl() }}
{{ item.myLinkField.hasElement() }}
{{ item.myLinkField.isEmpty() }}

Use the getLink utility function to render a full html link:, (*8)

{{ item.myLinkField.getLink() }}

You can pass the desired content of the link as a string, e.g., (*9)

{{ entry.linkField.getLink('Imprint') }}

You may also pass an array of attributes. When doing this you can override the default attributes href and target. The special attribute text will be used as the link content., (*10)

{{ entry.linkField.getLink({
  class: 'my-link-class',
  target: '_blank',
  text: 'Imprint',
}) }}

To get the CTA as a span (eg to use in clickable blocks), you can use the getSpan() function., (*11)

{{ entry.linkField.getSpan({
  class: 'my-link-class',
  text: 'Imprint',
}) }}

Configuration

Custom classes

Add custum classes to the dropdown menu., (*12)

  1. Add cta.php to /config
  2. Declare your classes:
<?php

return [
    'classes' => [
        'btn'                   => 'Primary',
        'btn btn--secondary'    => 'Secondary'
    ]
];

Linking between sites

By default, linking to entries from another site is not enabled. To make this work, you can use this config setting:, (*13)

<?php

return [
    'crossSiteLinking' => true
];

Credits

Heavily inspired by sebastian-lenz/craft-linkfield., (*14)

The Versions

26/07 2018

dev-master

9999999-dev

Call to action & link fields made easy

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft cta

26/07 2018

dev-develop

dev-develop

Call to action & link fields made easy

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft cta

26/07 2018

1.0.0

1.0.0.0

Call to action & link fields made easy

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft cta