Samples for using conditionals c. in shortcodes
As we use if.* shortcodes in Awesome Enterprise, similarly we can use conditionals using “c.” within individual shortcodes to decide when they will get executed.
Here is a quick list of all the samples for using “c.*” conditions. These are Strict Checks, which means we match both the Value and the Datatype. if needed you can explicitly set the datatype.
Conditions for checking Equal & Not Equal
1 2 3 4 5 6 7 8 9 10 11 12 |
[module.set x='testing' /] [module.echo x /] <li> <strong>c.cond='s:{module.x}' c.eq='testing'</strong> [do.test c.cond='s:{module.x}' c.eq='testing'] I am equal to testing. [/do.test] </li> <li> <strong>c.cond='s:{module.x}' c.neq='test'</strong> [do.test c.cond='s:{module.x}' c.neq='test'] I am not equal to test. [/do.test] </li> |
Conditions for checking Greater than & Less than
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[module.set success='I suceeded' failed='I failed' /] [module.set y='5000' /] <li> <strong>c.cond="n:{module.y}" c.gt="n:2000" </strong> [do.test c.cond="n:{module.y}" c.gt="n:2000" ] 5000 is greater than 2000. [/do.test] Result: [module.success c.cond="n:{module.y}" c.gt="n:2000" /] </li> <li> <strong>c.cond="n:{module.y}" c.lt="n:6000" </strong> [do.test c.cond="n:{module.y}" c.lt="n:6000" ] 5000 less than 6000. [/do.test] Result: [module.success c.cond="n:{module.y}" c.lt="n:6000" /] </li> <li> <strong>c.cond="n:{module.y}" c.lte="n:5000" </strong> [do.test c.cond="i:{module.y}" c.lte="i:5000" ] 5000 less than equal to 5000. [/do.test] Result: [module.success c.cond="i:{module.y}" c.lte="i:6000" /] </li> <li> <strong>c.cond="n:{module.y}" c.gte="n:4000" </strong> [do.test c.cond="n:{module.y}" c.gte="5000" ] 5000 greater than equal to 5000. [/do.test] Result: [module.success c.cond="n:{module.y}" c.gte="n:4000" /] </li> |
Conditions for checking Null
These checks use the is_null function of PHP
1 2 3 4 5 6 7 8 9 |
[str.create hello o.set=module.x_str /] [arr.set module.arrset a={module.x_str} b='' c="hello"/] <strong>c.null='module.x_str'</strong>: Result:[module.success c.null='module.x_str'/]<br /> <strong>c.null='null'</strong>: Result:[module.success c.null='null'/] <br /> <strong>c.not_null='module.arrset'</strong> Result:[module.success c.not_null='module.arrset'/] |
Conditions for checking Whitespaces
1 2 3 4 5 6 |
[module.set success='I suceeded' failed='I failed' /] [str.create main=' ' o.set=module.whitespaces /] <li><strong> c.ws='module.whitespaces'</strong> Result:[module.success c.ws='module.whitespaces'/]</li> <li><strong> c.not_ws='module.failed'</strong> Result:[module.success c.not_ws='module.failed'/]</li> |
Conditions for checking Empty
It internally uses empty PHP function.
1 2 3 4 5 6 7 8 |
[str.create hello o.set=module.x_str /] [arr.set module.arrset a={module.x_str} b='' c="hello"/] <li> <strong>c.empty='module.x_str'</strong> Result:[module.success c.empty='module.x_str'/]</li> <li> <strong>c.empty='module.arrset.b'</strong> Result:[module.success c.empty='module.arrset.b'/]</li> <li> <strong>c.not_empty='module.arrset'</strong> Result:[module.success c.not_empty='module.arrset'/]</li> |
Conditions for checking Exists
1 2 3 4 5 6 7 8 9 10 11 |
[module.set success='I suceeded' failed='I failed' /] [str.create hello o.set=module.x_str /] [arr.set module.arrset a={module.x_str} b='' c="hello"/] <li> <strong>c.request_exists='req'</strong> Result:[module.success c.request_exists='req' /] : [request.get req /]</li> <li> <strong>c.request_not_exists='req'</strong> Result:[module.success c.request_not_exists='req' /]</li> <li> <strong>c.exists='module.x_str'</strong> Result:[module.success c.exists='module.x_str' /]</li> <li> <strong> c.not_exists='module.b'</strong> Result:[module.success c.not_exists='module.b' /]</li> |
Conditions for checking Contains
This is not a strict check, so it will not check for datatypes.
1 2 3 4 5 6 7 8 9 10 11 |
[module.set success='I suceeded' failed='I failed' /] [str.create hello o.set=module.x_str /] [arr.set module.arrset a={module.x_str} b='' c="hello"/] <li> <strong> c.contains='s:hello' c.haystack='s:hello,hi,hope'</strong> Result:[module.success c.contains='s:hello' c.haystack='s:hello,hi,hope' /]</li> <li> <strong> c.contains='s:hell' c.haystack='module.arrset'</strong> Result:[module.success c.contains='s:hell' c.haystack='module.arrset' /]</li> <li> <strong> c.not_contains='s:hello' c.haystack='s:hello,hi,hope'</strong> Result:[module.success c.not_contains='s:hello' c.haystack='s:hello,hi,hope' /]</li> <li> <strong> c.not_contains='s:hell' c.haystack='module.arrset'</strong> Result:[module.success c.not_contains='s:hell' c.haystack='module.arrset' /]</li> |
Conditions for checking User
This conditional can be used to check the capability of the current user. Behind the scene, it uses current_user_can WordPress function, so you can also check user capabilities. In the case of logged_in the “yes” is irrelevant, you can write “x” and it will still behave the same.
1 2 3 4 5 6 7 8 9 |
[module.set success='I suceeded' failed='I failed' /] <li> <strong> c.user_can='administrator' </strong> Result:[module.success c.user_can='administrator' /]</li> <li> <strong> c.user_cannot='subscriber' </strong> Result:[module.success c.user_cannot='subscriber' /]</li> <li> <strong> c.logged_in='yes' </strong> Result:[module.success c.logged_in='yes' /]</li> <li> <strong> c.not_logged_in='yes' </strong> Result:[module.success c.not_logged_in='yes' /]</li> |
Conditions for checking Yes/No, True/False, Odd/Even
As mentioned above they check for the data type as well, so yes/no is string comparison while true/false is bool and odd/even is an int comparison. You will have to cast them appropriately when doing the comparisons.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[module.set success='I suceeded' failed='I failed' /] [module.set y='5000' /] [int.create 6250 o.set=module.int_even /] [num.create 123.00 o.set=module.num_odd /] [bool.create true o.set=module.y_bool /] <li> <strong> c.true="module.y_bool" </strong> Result:[module.success c.true="module.y_bool" /]</li> <li> <strong> c.true="b:5" </strong> Result:[module.success c.true="b:5" /]</li> <li> <strong> c.true="n:5" </strong> Result:[module.success c.true="n:5" /]</li> <li> <strong> c.false="n:5" </strong> Result:[module.success c.false="n:5" /]</li> <li> <strong> c.false="b:5" </strong> Result:[module.success c.false="b:5" /]</li> <li> <strong> c.false="module.lapp_id" </strong> Result:[module.success c.false="module.y" /]</li> <li> <strong> c.yes='module.lapp_id' </strong> Result:[module.success c.yes='module.y' /]</li> <li> <strong> c.yes='s:yes </strong> Result:[module.success c.yes='s:yes' /]</li> <li> <strong> c.yes='yes' </strong> Result:[module.success c.yes='yes' /]</li> <li> <strong> c.no='module.lapp_id' </strong> Result:[module.success c.no='module.y' /]</li> <li> <strong> c.no='s:no' </strong> Result:[module.success c.no='s:no' /]</li> <li> <strong> c.no='no' </strong> Result:[module.success c.no='no' /]</li> <li> <strong> (Int Check - Casted to Int) c.even=module.int_even </strong> Result:[module.success c.even='module.int_even' /]</li> <li> <strong> c.even=i:{module.int_even} </strong> Result:[module.success c.even=i:{module.int_even} /]</li> <li> <strong> c.even=i:50 </strong> Result:[module.success c.even=i:50 /]</li> <li> <strong> c.odd=module.int_even </strong> Result:[module.success c.odd=module.int_even /]</li> |
Conditions for checking Datatypes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[module.set success='I suceeded' failed='I failed' /] [module.set y='5000' /] [str.create hello o.set=module.x_str /] [arr.set module.arrset a={module.x_str} b='' c="hello"/] [int.create 6250 o.set=module.int_even /] [num.create 123.00 o.set=module.num_odd /] [bool.create true o.set=module.y_bool /] <li><strong> c.arr='module.arrset'</strong> Result:[module.success c.arr='module.arrset'/]</li> <li><strong> c.not_arr='module.arrset'</strong> Result:[module.success c.not_arr='module.arrset'/]</li> <li><strong> c.str='module.x_str'</strong> Result:[module.success c.str='module.x_str'/]</li> <li><strong> c.not_str='module.arrset'</strong> Result:[module.success c.not_str='module.arrset'/]</li> <li><strong> c.bool='module.y_bool'</strong> Result:[module.success c.bool='module.y_bool'/]</li> <li><strong> c.not_bool='module.x_str'</strong> Result:[module.success c.not_bool='module.x_str'/]</li> <li><strong> c.int='module.int_even'</strong> Result:[module.success c.int='module.int_even'/]</li> <li><strong> c.not_int='module.num_odd'</strong> Result:[module.success c.not_int='module.num_odd'/]</li> <li><strong> c.num='module.num_odd'</strong> Result:[module.success c.num='module.num_odd'/]</li> <li><strong> c.not_num='module.num_odd'</strong> Result:[module.success c.not_num='module.num_odd'/]</li> <li><strong> c.obj='module.num_odd'</strong> Result:[module.success c.obj='module.num_odd'/]</li> <li><strong> c.not_obj='module.arrset'</strong> Result:[module.success c.not_obj='module.arrset'/]</li> <li><strong> c.zero='n:0'</strong> Result:[module.success c.zero='n:0'/]</li> <li><strong> c.positive='module.y'</strong> Result:[module.success c.positive='module.y'/]</li> <li><strong> c.negative='module.y'</strong> Result:[module.success c.negative='module.y'/]</li> |
Conditions for checking Device
This uses Mobile_Detect PHP class to check for the device.
1 2 3 4 5 |
[module.set success='I suceeded' failed='I failed' /] <li> <strong> c.device='s:desktop' </strong> Result:[module.success c.device='s:desktop' /]</li> <li> <strong> c.device='s:tablet,mobile' </strong> Result:[module.success c.device='s:tablet,mobile' /]</li> |
Conditions for and.* & or.*
We can combine checks together using add.* & or.* conditionals as shown in examples below
1 2 3 4 |
<li> <strong> c.device='s:desktop' and.logged_in='yes' </strong> Result:[module.success c.device='s:desktop' and.logged_in='yes' /]</li> <li> <strong> c.device='s:mobile' or.exists='module.arrtest.f' </strong> Result:[module.success c.device='s:mobile' or.exists='module.arrtest.f' /]</li> |
Conditions for ignore
you can ignore the execution of any awesome shortcode by using c.ignore=yes, here “yes” is just a filler, to avoid the limitation of shortcode attributes.
1 |
[env.dump c.ignore='no'] this will not dump the output. |