GithubHelp home page GithubHelp logo

nystudio107 / richvariables Goto Github PK

View Code? Open in Web Editor NEW
44.0 4.0 2.0 457 KB

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

License: MIT License

PHP 48.38% CSS 5.93% JavaScript 36.31% HTML 9.37%
craftcms craft-plugin rich-text variables

richvariables's Introduction

No Maintenance Intended

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.

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.

Rich Variables plugin for Craft CMS

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

Related: Rich Variables for Craft 3.x

Screenshot

Installation

To install Rich Variables, follow these steps:

  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.

Rich Variables Overview

Rich Variables allows you to easily use Craft Globals as variables in Rich Text fields.

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.

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 Settingsโ†’Globals:

Screenshot

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.

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 Settingsโ†’Rich Variables and choose your Globals set, then click on Save:

Screenshot

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.

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

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

Note that richvariables was added to the plugins array above.

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.

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:

Screenshot

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.

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:

Screenshot

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

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

Screenshot

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.

Nice.

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.

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.

Rich Variables Roadmap

Some things to do, and ideas for potential features:

  • 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

richvariables's People

Contributors

khalwat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

richvariables's Issues

On login, sometimes we're redirected to the JSON output

Sometimes, seemingly when attempting to login, we're redirected to the JSON output of the Rich Variables controller.

I think this is due to the XHttpRequest in the JavaScript. Attempt to mitigate this by only loading the JavaScript if a logged in user session is active.

After inserting, saving, and saving again, the "dynamicness" is lost

Steps to reproduce:

  1. Insert a variable tag
  2. Save
  3. Save again
  4. Changing the variable doesn't update the tag (in the preview or on the site)

Appears the "preview" of the tag is being saved over the actual tag. Guessing it's something to do with Redactor or the tag previewer?

Craft CMS: 2.6.2983
Rich Variables: 1.0.5
Plugins enabled: Blueprint, Control Panel Nav, Expanded Singles, Minify, Pimp My Matrix, Rich Variables, SEOmatic, Simple Sharing

Extend to support filter for variables in other field types

Is it possible that this plugin could look to be extended to support a filter to allow global variables in other field types, for example if I have a plain text field in a section and I typed {globalHandle.fieldName} in the input, it would output the value of the global variable.

In the template it could work as {{ entry.fieldName|rv }}

roadmap: category fields

I see the note in your roadmap. I'd love to have fields from category entries embeddable into rich text fields (currently have a use case where this would be fantastic). But will this even be possible? category is notably missing as a type in the documentation on Reference Tags.

Some feature requests

Awesome plugin! Rich Variables works exactly as described. Just today a client asks me exactly about this kind of functionality.

Some feature requests:

  • global URL variables for link hrefs (not sure how the Redactor UX could be)
  • setting to get rid of <ins> or change the element
  • multiple configurations with different global sets (e.g. per channel settings or multiple Redactor plugins)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.