2017 © Pedro Peláez
 

craft-plugin richvariables

Allows you to easily use Craft Globals as variables in Rich Text fields

image

nystudio107/richvariables

Allows you to easily use Craft Globals as variables in Rich Text fields

  • Saturday, February 25, 2017
  • by khalwat
  • Repository
  • 1 Watchers
  • 44 Stars
  • 717 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 4 Open issues
  • 8 Versions
  • 10 % Grown

The README.md

No Maintenance Intended, (*1)

DEPRECATED

This Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons., (*2)

The Craft CMS 3.x version of this plugin can be found here: craft-richvariables and can also be installed via the Craft Plugin Store in the Craft CP., (*3)

Rich Variables plugin for Craft CMS

Allows you to easily use Craft Globals as variables in Rich Text fields, (*4)

Related: Rich Variables for Craft 3.x, (*5)

Screenshot, (*6)

Installation

To install Rich Variables, follow these steps:, (*7)

  1. Download & unzip the file and place the richvariables directory into your craft/plugins directory
  2. -OR- do a git clone https://github.com/nystudio107/richvariables.git directly into your craft/plugins folder. You can then update it with git pull
  3. -OR- install with Composer via composer require nystudio107/richvariables
  4. Install plugin in the Craft Control Panel under Settings > Plugins
  5. The plugin folder should be named richvariables for Craft to see it. GitHub recently started appending -master (the branch name) to the name of the folder for zip file downloads.

Rich Variables works on Craft 2.5.x and Craft 2.6.x., (*8)

Rich Variables Overview

Rich Variables allows you to easily use Craft Globals as variables in Rich Text fields., (*9)

For instance, you might have loan rates that appear in the body of multiple Rich Text fields, and maybe even in multiple places in each field. When it comes time to update those loan rates, you can just change them in your Globals set, and they will be automatically updated wherever they are used in your Rich Text fields., (*10)

Configuring Rich Variables

To configure Rich Variables, first you'll need to create a Globals set (if you don't have one already) by clicking on SettingsGlobals:, (*11)

Screenshot, (*12)

You can put any kinds of fields that you want into your Globals set, but Rich Variables only recognizes the following FieldTypes currently: PlainText, Number, Date, Dropdown, and Preparse., (*13)

Next, you need to tell Rich Variables which Globals set (you can have an arbitrary number of them) that it should use. To do this, click on SettingsRich Variables and choose your Globals set, then click on Save:, (*14)

Screenshot, (*15)

Finally, we'll need to let Redactor (the Craft 2.x Rich Text editor) know that we want to use the Rich Variables plugin. You can do this by editing the Redactor settings in craft/config/redactor/. Make sure you edit the settings that your Rich Text fields use to add richvariables to the plugins array., (*16)

For example, here's what my Standard.json Redactor settings looks like:, (*17)

{
    "buttons": ["format","kbd","bold","italic","lists","link","file","horizontalrule"],
    "plugins": ["source","fullscreen","richvariables"]
}

Note that richvariables was added to the plugins array above., (*18)

If Rich Variables isn't appearing in your Rich Text fields, it's usually because the Rich Text fields aren't using the Redactor settings where you added richvariables to the plugins array., (*19)

Using Rich Variables

The setup was the hard part. Using Rich Variables is easy, just go to your Rich Text field, and click on the newly added Rich Variables icon to see a list of your Globals set variables:, (*20)

Screenshot, (*21)

Choose one to insert it into your Rich Text field. You'll see some code-looking stuff inserted, such as {globalset:737:loanName} in the example above., (*22)

This is actually a Reference Tag to the Globals set Element and Field that you chose. But that needn't concern you, because once you save the Entry, it will appear like this:, (*23)

Screenshot, (*24)

...with a tokenized display of the actual value that is in your Globals set Fields. If you change the values in your Globals set Fields, they will automatically be updated everywhere they are used in your Rich Text fields., (*25)

On the frontend, the display of the Rich Text field will also automatically include the Globals set values, and might look something like this:, (*26)

Screenshot, (*27)

The fun thing about the way Rich Variables works is that since it leverages the built-in Craft functionality of Reference Tags, even if you uninstall the Rich Variables plugin, everything will continue to work., (*28)

Nice., (*29)

Miscellanea

To display itself in a tokenized way, Rich Variables wraps the inserted variables in <ins></ins> tags. The default styling for these seldom-used tags is text-decoration: underline; in many browsers. So for frontend display, you might need to add some CSS to override this if you don't want them underlined., (*30)

Redactor can be a little weird with inline styles; this isn't anything specific to Rich Variables. What I typically do is when I want to insert an inline style, I type two spaces, then the left-arrow key, and then I insert my inline style in Redactor. This ensures that there is a space on either side of the inline style, and prevents some formatting headaches., (*31)

Rich Variables Roadmap

Some things to do, and ideas for potential features:, (*32)

  • Rich Variables could potentially have different Global sets for different Channels
  • We could allow for things other than Global sets to be available for insertion, such as Entry values, Categories, etc.

Brought to you by nystudio107, (*33)

The Versions

25/02 2017

dev-master

9999999-dev

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires

 

25/02 2017

dev-develop

dev-develop

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires

 

24/02 2017

1.0.5

1.0.5.0

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires

 

09/02 2017

1.0.4

1.0.4.0

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires

 

07/02 2017

1.0.3

1.0.3.0

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires

 

06/02 2017

1.0.2

1.0.2.0

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires

 

05/02 2017

1.0.1

1.0.1.0

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires

 

04/02 2017

1.0.0

1.0.0.0

Allows you to easily use Craft Globals as variables in Rich Text fields

  Sources   Download

The Requires