Skip to content

jools-r/jcr_link_custom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jcr_link_custom

Adds up to five extra custom fields of up to 255 characters to the Content › Links panel along with corresponding tags to output the custom field and to test if it contains a value or matches a specific value.

Use cases

Use whenever extra information needs to be stored with a link. For example:

  • Store a txp image ID number and use it to attach a logo to a link.
  • Store associated details, for example the location of a linked organisation.
  • ...

Installation / Deinstallation / Upgrading

Installation

Paste the .txt installer code into the Admin › Plugins panel, or upload the plugin's .php file via the Upload plugin button, then install and enable the plugin.

Upgrading

The plugin automatically migrates custom field data and the database structure from the earlier single custom field variant (v0.1) to the new format. No changes are needed to the public tags as the new default settings correspond to the old tag. Nevertheless, it is always advisable to make a database backup before upgrading.

De-installation

The plugin cleans up after itself: deinstalling (deleting) the plugin removes the extra columns from the database as well as custom field names and labels. To stop using the plugin but keep the custom field data in the database, just disable (deactivate) the plugin but don't delete it.

Plugin tags

jcr_link_custom

Outputs the content of the link custom field.

Tag attributes

name
Specifies the name of the link custom field.
Example: Use name="image_id" to output the image_id custom field. Default: jcr_link_custom_1.

escape
Escape HTML entities such as <, > and & prior to echoing the field contents.
Supports extended escape values in txp 4.8+
Example: Use escape="textile" to convert textile in the value. Default: none.

default
Specifies the default output if the custom field is empty
Example: Use default="123" to output "123", e.g. for use as the default image ID number. Default: empty.

wraptag
Wrap the custom field contents in an HTML tag
Example: Use wraptag="h2" to output <h2>Custom field value</h2>. Default: empty.

class
Specifies a class to be added to the wraptag attribute
Example: Use wraptag="p" class="intro" to output <p class="intro">Custom field value</p>. Default: empty

jcr_if_link_custom

Tests for existence of a link custom field, or whether one or several matches a value or pattern.

Tag attributes

name
Specifies the name of the link custom field.
Example: Use name="image_id" to output the image_id custom field. Default: jcr_link_custom_1.

value
Value to test against (optional).
If not specified, the tag tests for the existence of any value in the specified link custom field.
Example: Use value="english" to output only those links whose "language" link custom field is english. Default: none.

match
Match testing: exact, any, all, pattern. See the docs for if_custom_field.
Default: exact.

separator
Item separator for match="any" or "all". Otherwise ignored.
Default: empty.

Examples

Example 1

Produce a list of linked partner logos (from link assigned to the link category "partners"):

<txp:linklist wraptag="ul" break="li" category="partners">
    <txp:jcr_if_link_custom name="image_id" value="">
        <a href="<txp:link_url />" title="<txp:link_name />"><txp:link_name /></a>
    <txp:else />
        <a href="<txp:link_url />" title="<txp:link_name />"><txp:image id='<txp:jcr_link_custom name="image_id" />' limit="1" /></a>
    </txp:jcr_if_link_custom>
</txp:linklist>

where the image_id link custom field is used to store the Image ID# of the logo.

Custom field labels

The label displayed alongside the custom field in the edit image panel can be changed by specifying a new label using the Install from Textpack field in the Admin › Languages panel. Enter your own information in the following pattern and click Upload:

#@owner jcr_link_custom
#@language en, en-gb, en-us
#@link
jcr_link_custom_1 => Your label
jcr_link_custom_2 => Your other label

replacing en with your own language and Your label with your own desired label.

Changelog and credits

Changelog

  • Version 0.2.4 -- 2020/12/20 -- Align with other custom field plugins
  • Version 0.2.3 -- 2020/06/29 -- Tag registration + textpack fixes
  • Version 0.2.2 -- 2020/06/27 -- Handle migration from previous versions of the plugin on install
  • Version 0.2.1 -- 2020/06/27 -- Fix for missing custom_field name vs. missing value for cf
  • Version 0.2 -- 2020/06/23 -- Expand to handle multiple custom fields + migrate from v1
  • Version 0.1.1 -- 2016/12/0518 -- Remedy table not being created on install
  • Version 0.1 -- 2016/03/04 -- First release

Credits

Robert Wetzlmayr's wet_profile plugin for the starting point, and further examples by Stef Dawson and Jukka Svahn.

About

Adds up to 5 link custom fields to Textpattern

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages