[Part 4.2] Building A Website in Craft CMS - (Useful Plugins Part 2 - Reasons)

in #craftcms7 years ago

In [Part 4] we looked at NEO one of the most powerful fieldtype plugins available for CraftCMS, we saw all it could do and got it installed on our build.

In [Part 3] we installed Craft and removed the demo fields/sections and templates so that we have an absolutely bare platform to start building upon.

In [Part 2] we covered some of the basics of using the Twig template engine, setting up advanced routes, and of course the eye candy Live Preview.

In [Part 1] we went over the very basics of Craft CMS, what it is, pricing, sections, assets, globals, entry-types, fields, and field-groups.

In [Part 4.2] we're going to checkout another great plugin that enhances the process even further: Reasons. This plugin can be used in conjunction or independent of NEO, but it sure does make working with NEO even sexier.

Reasons

Reasons allows us to set conditional rules for when to show or hide additional fields. For instance if you had an event content-type and sometimes events were free to attend, and other times they cost money, there is no need to show a field to gather price or discount data if the event were free, so hide it when not necessary.

Installing

  • Start by downloading the necessary files by clicking here.
  • Unzip the file and open Reasons-Craft-Master
  • Find the folder reasons and upload it to your server in craft/plugins/
  • Open your dashboard and navigate to Settings > Plugins
  • Find reasons and click install

It is now available to be used, it was that simple.

Setting the Rules

As our previous article was about NEO we'll focus on using Reasons with it. using the same setup from our last article we'll open up our Neo field where in the demo for this article I've already created and added several fields.
Screen Shot 2017-08-16 at 7.03.33 PM.png

You see where it says Edit Conditionals? That's reasons in action.

Now in the above screenshot, you'll notice that the field where we clicked the gear to see the settings is alone in that particular tab. There are no other fields present for the tab. If we click to Edit Conditionals then, no options will be available to us.
Screen Shot 2017-08-16 at 7.06.21 PM.png

The platform is smart it knows that it would not make any sense to set conditionals there, and so it doesn't even offer the opportunity for us to confuse ourselves.

If we were to click however on a field in a tab with multiple other fields, like so:
Screen Shot 2017-08-16 at 7.11.24 PM.png

We then see that we have some rules to set if desired:
Screen Shot 2017-08-16 at 7.08.41 PM.png

If we click to Add rules we are presented with the other fields available within that tab, and given the options available for those fields.
Screen Shot 2017-08-16 at 7.14.04 PM.png

In that example, there are 4 fields available and I've added a rule that includes all of them for demonstration purposes.
  • Anchor name is a plain text field and so we are presented with a drop down to select is equal to or is not equal to and a text field to enter the value we want to check against. As a tribute to my good friend @descterity, I've entered Senior Pogi (Mr. Handsome) which is the name I've given him on Facebook Chat. That rule then only will show the Markdown field, which is the one we are setting the conditionals for, if the field Anchor name is equal to "Senior Pogi".
  • Fixed position? is a lightswitch field which only provides 2 values, on or off. We are therefor provided a dropdown field to select from the available options, and NOT a text-field which could cause inaccurate returns. As you can see we've now added a rule to check if Fixed position? is equal to off.
  • Custom class is another plain text field just like Anchor name above. For this rule we will check to make sure that Custom class is not equal to "eggs".
  • Color is a drop-down field where we have setup multiple pre-defined colors to be selected from the user. For the final rule we will check to see if Color is equal to Olive.

With those 4 rules set, the Markdown field will ONLY appear if:

  • Anchor name is equal to "Senior Pogi".
  • Fixed position? is equal to off.
  • Custom class is not equal to "eggs"
  • Color is equal to Olive.

If even a single one of those rules is not true, the Markdown field does not appear.

This setup allows us to build dynamic content-editors for the Site Owner/Content Manager, and only present them with the information they need, when they need it, not letting too many options jump out into their face and slowing down their efficiency due to choice-paralysis or confusion. Pretty great right!?

There is no additional code we'll have to worry about for this particular plugin as it is all handled strictly within the dashboard.

I HOPE YOU ENJOYED & LEARNED SOMETHING!

As always If you've reached it to the end of the article, given it's not particularly short, I'm going to assume that you enjoyed reading it. Please go ahead and UPVOTE the post, RESTEEM if you think your followers would also find value in it, and make sure to @FOLLOW ME to make sure you don't miss the upcoming articles in this series where we'll get much more in depth and even build a site together from the ground up! EXCITING TIMES!

Thanks to all of my followers both new and old, I hope to continue to bring you quality content that interest you, feel free to comment any requests for any particular topic you'd like to read or learn about if you believe I may be able to answer it for you. Cheers!

Sort:  

appreciate the tribute!

all the best to all you do 🌄

excellent post @sasha.shade one of the genuis i know when comes to english grammar hehehe and delivered writing a good content ..keep it up !!!

very smart guy, I just write and make up things, my hat off to you, and now following you

nice upvoted

This post has received a 1.56 % upvote from @drotto thanks to: @banjo.

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by sasha.shade from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews/crimsonclad, and netuoso. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

Congratulations @sasha.shade! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.033
BTC 64010.98
ETH 2791.72
USDT 1.00
SBD 2.65