WEBVTT

00:04.530 --> 00:10.320
As you might have noticed by now that engine X configuration syntax closely resembles that of a programming

00:10.320 --> 00:17.610
language implementing in some ways the concept of scope includes and in this lesson in variables and

00:17.610 --> 00:22.290
conditionals variables exist in two forms variables.

00:22.290 --> 00:29.460
We set ourselves and engine exis own built in variables we can find a list of these engine X variables

00:29.490 --> 00:37.680
in the engine X dot org documentation alphabetical index of variables which lists each of the available

00:37.680 --> 00:45.690
variables with the module that makes it available modules like hgt underscore core and h.t. dp log.

00:45.790 --> 00:50.420
Really being part of engine X so you don't have to manually add them.

00:50.580 --> 00:53.410
Now these native variables can be extremely useful.

00:53.430 --> 00:58.470
So let's switch back to that configuration file and see how we could use them.

00:58.470 --> 01:06.220
I'll clear all of these locations from the previous lesson create a new location for Slash inspect.

01:06.450 --> 01:09.210
And in this location simply return a few of these.

01:09.210 --> 01:17.900
Engine X variables return status 200 a string and using double quotation marks.

01:17.910 --> 01:21.750
We can directly embed variables into this response string.

01:22.110 --> 01:28.470
First one I'll add is the host variable variables being prefixed with a dollar sign.

01:28.470 --> 01:30.620
Add a new line character.

01:30.630 --> 01:40.960
You are a new line and ARGs which is the requests query string save this and reload the configuration.

01:42.640 --> 01:44.890
Navigate to that new location.

01:45.490 --> 01:46.950
Slash inspect.

01:47.990 --> 01:50.780
And we see each variable on its own line.

01:50.780 --> 01:56.150
The host which is the server I see as I'm not using the domain name and the request.

01:56.150 --> 01:58.530
You are I slash inspect.

01:58.550 --> 02:02.780
Of course we didn't pass a query string so the args variable is empty.

02:02.780 --> 02:12.470
But if I add query name equals Ray that's now also returned albeit in its complete string form.

02:12.470 --> 02:18.050
We can however use a variation of the args variable to get individual query parameters.

02:18.080 --> 02:20.470
I'll change this string to name.

02:21.390 --> 02:23.730
Argh underscore name.

02:23.940 --> 02:30.960
So based on the query string engine it compiles a named variable for each parameter prefixed with Arg

02:31.560 --> 02:33.570
save and reload this.

02:34.520 --> 02:38.890
Reload and this time we get the value of the name parameter.

02:38.930 --> 02:46.160
So already a very powerful feature set of engine X engine X also allows us to perform basic conditionals

02:46.400 --> 02:53.000
or if statements which most commonly will be used in conjunction with one of these variables before

02:53.000 --> 02:54.150
I demonstrate however.

02:54.170 --> 03:01.640
Note that the use of engine X conditionals inside location contexts is highly discouraged as this can

03:01.640 --> 03:04.030
lead to some very unexpected behaviour.

03:04.190 --> 03:09.440
Now the technicalities of this is beyond the scope of what we can cover here but if you'd like to read

03:09.440 --> 03:14.770
more on the subject I've linked to a very detailed explanation in the list and resources.

03:15.020 --> 03:15.430
Righto.

03:15.440 --> 03:21.620
Outside of this location context then I'll create a conditional which for the sake of demonstrating

03:21.930 --> 03:27.300
chicks are hypothetical AP Iki if with braces.

03:27.410 --> 03:32.640
Note the space between the F and the braces being required for this syntex to be valid.

03:32.920 --> 03:35.870
Argh underscore a p Iki.

03:35.880 --> 03:43.760
So checking the value of the API key query parameter not equal to 1 2 3 4.

03:43.820 --> 03:50.810
Meaning if the user does not pass the value 1 2 3 4 as the API key parameter in the query string to

03:50.870 --> 03:57.020
any you are a return of foro 1 which is the unauthorized status code.

03:57.020 --> 03:59.600
Incorrect API key.

03:59.600 --> 04:00.980
Save this.

04:03.300 --> 04:07.740
Reload with alt that API parameter key this time just requesting the root.

04:07.740 --> 04:08.300
You are right.

04:08.310 --> 04:11.240
So their demo site and we're denied.

04:11.370 --> 04:15.150
As per that conditional add the API key parameter.

04:15.150 --> 04:22.980
However with a value of 1 2 3 4 and were served indexed update the amelle as the conditional did not

04:22.980 --> 04:28.860
evaluate to true image and style sheet simply being missing as the internal requests for those didn't

04:28.860 --> 04:31.080
include the API key parameter.

04:31.420 --> 04:36.960
OK as I mentioned we can also set our own variables within range and X configuration.

04:36.960 --> 04:43.400
I'll get rid of all this and to create a new variable we can say set the variable name.

04:43.440 --> 04:47.220
I'll make this weekend and the variable value.

04:47.430 --> 04:50.060
No so no equals sign.

04:50.070 --> 04:56.910
Just the standard engine X director format variables can be set to simple strings such as this example

04:57.360 --> 04:59.520
integers or booleans.

04:59.520 --> 05:06.270
True and false then for another hypothetical use case we can check if it is weakened by creating an

05:06.330 --> 05:11.940
if statement and using the date underscore local engine x variable.

05:11.940 --> 05:18.930
This variable holding an ISO date time string for the local time and instead of a simple equals or not

05:18.960 --> 05:20.400
equals operator.

05:20.430 --> 05:28.860
We can use a regular expression as with location contexts folder checking on this variable for Saturday

05:29.220 --> 05:30.940
or Sunday.

05:31.170 --> 05:36.130
In which case if this is true set weekend 2 Yes.

05:37.460 --> 05:40.510
So starting out we said weekend to be No.

05:40.640 --> 05:46.970
Check the local date to see if it is in fact Saturday or Sunday which if it is we changed the value

05:46.970 --> 05:48.870
of weekend to be yes.

05:49.570 --> 05:52.720
Change this location to is WEEKEND.

05:53.300 --> 05:56.490
Returning two hundred and the weekend variable.

05:56.520 --> 05:57.990
So yes or no.

05:58.930 --> 06:01.540
Save and reload the configuration.

06:03.170 --> 06:09.850
Navigate to that you are I is under school weekend and it being a Monday at the time of recording this

06:10.150 --> 06:11.540
we get no.

06:13.190 --> 06:16.770
Change the condition to check for Monday instead then.

06:17.670 --> 06:19.910
I'll rename this variable to mun.

06:21.840 --> 06:25.440
And said the location to is Monday.

06:26.800 --> 06:27.860
Reload.

06:30.290 --> 06:32.490
Navigate to is Monday.

06:34.630 --> 06:38.320
And this time we get yes as this conditional evaluator.

06:38.330 --> 06:44.380
True true and updated the variable to be yes in the next place and we'll use some of these variables

06:44.380 --> 06:46.930
to learn about rewrites and redirects.
