Silverstripe module that allows for easy adding of links to the CMS

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0


2.0.0 2023-08-18 08:24 UTC

This package is auto-updated.

Last update: 2023-11-18 08:55:33 UTC


Adds easy to implement link options to the CMS


  • Choose from the following options: None, Page, File, URL
  • Option to remove fields that don't apply to your implementation
  • Can output link straight to template


$ composer require bigfork/silverstripe-linkset

How to use

You will need to create a $has_one relation on your data object

private static array $has_one = [
    'ButtonLink' => LinkSet::class,

Then add the LinksetField to your fieldlist

        LinksetField::create($this, 'ButtonLink'),

LinkSetField constructor accepts five params:

  • DataObject $data - The object the relation is on $this
  • string $name - Name of the field should match the relation key
  • ?string $title (optional) - Title of the field, will set the heading above the fields
  • array $fieldsToRemove (optional) - To remove Title from the list of fields pass in array for example ['Title']. Possible options to remove are:
    • Title
    • LinkType
    • LinkURL
    • LinkTarget
    • LinkedPageID
    • LinkedFile
  • array $typesToRemove (optional) - Remove link types from the radio, to remove the option for None pass in array for example ['None']. Possible options to remove are:
    • None
    • Page
    • File
    • URL

With all the parameters your code may look like:

        LinksetField::create($this, 'ButtonLink', 'Button link', ['Title'], ['None']),

Using in templates

You can output the link in the template by calling the relation

{$ButtonLink.AddExtraClass('button button--primary')}

This will output a simple anchor tag with the all the fields that had been set on the LinkSetField group.

Custom anchors can be done by accessing the fields through the relation as normal

<% with $ButtonLink %>
    <% if $LinkTarget %> target="{$LinkTarget}"<% end_if %>
    <% if $LinkType = 'File' %> download<% end_if %>
<% end_with %>