PHPackages                             statikbe/craft-cta-field - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. statikbe/craft-cta-field

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

statikbe/craft-cta-field
========================

Call to action &amp; link fields made easy

2.4.2(6mo ago)010.8k[1 issues](https://github.com/statikbe/craft-ctafield/issues)MITPHP

Since Jul 26Pushed 6mo ago7 watchersCompare

[ Source](https://github.com/statikbe/craft-ctafield)[ Packagist](https://packagist.org/packages/statikbe/craft-cta-field)[ RSS](/packages/statikbe-craft-cta-field/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (1)Versions (25)Used By (0)

CTA field plugin for Craft
==========================

[](#cta-field-plugin-for-craft)

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 3.0.0 or later.

Migrating to [verbb/hyper](https://github.com/verbb/hyper)
----------------------------------------------------------

[](#migrating-to-verbbhyper)

In an effort to phase out the usage of this plugin, we've added 2 console commands to migration the fields and their content to [Hyper](https://github.com/verbb/hyper).

These are the steps you should follow:

- Install hyper
     `ddev composer require "verbb/hyper" -w && ddev exec php craft plugin/install hyper`
- Install Config Values Field
     `ddev composer require "statikbe/craft-config-values" -w && ddev exec php craft plugin/install config-values-field`
- Resave and check your supertable tables (visit `/admin/super-table/settings` and click both buttons)

Caution

If supertable is missing tables/columns, or entire fields are marked as missing - please fix that first before proceeding.

- Migrate field settings.
     `ddev craft cta/migrate/statik-cta-field`
     This will transform all your CTA fields to Hyper fields and update their project config files.
- Migratie field content.
     `ddev craft cta/migrate/statik-cta-content`
     You'll have to run this on each environment, but only **after** you ran the fields command or you deployed the changes.

Installation
------------

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require statikbe/craft-cta-field

    ```
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Link Field.

Templating
----------

[](#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.

```
Link

```

You can use the following accessors to get the different properties of the link:

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

```
{{ item.myLinkField.getLink() }}

```

You can pass the desired content of the link as a string, e.g.

```
{{ 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.

```
{{ 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.

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

```

Configuration
-------------

[](#configuration)

### Custom classes

[](#custom-classes)

Add custum classes to the dropdown menu.

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

```
