1 00:00:04,530 --> 00:00:10,320 As you might have noticed by now that engine X configuration syntax closely resembles that of a programming 2 00:00:10,320 --> 00:00:17,610 language implementing in some ways the concept of scope includes and in this lesson in variables and 3 00:00:17,610 --> 00:00:22,290 conditionals variables exist in two forms variables. 4 00:00:22,290 --> 00:00:29,460 We set ourselves and engine exis own built in variables we can find a list of these engine X variables 5 00:00:29,490 --> 00:00:37,680 in the engine X dot org documentation alphabetical index of variables which lists each of the available 6 00:00:37,680 --> 00:00:45,690 variables with the module that makes it available modules like hgt underscore core and h.t. dp log. 7 00:00:45,790 --> 00:00:50,420 Really being part of engine X so you don't have to manually add them. 8 00:00:50,580 --> 00:00:53,410 Now these native variables can be extremely useful. 9 00:00:53,430 --> 00:00:58,470 So let's switch back to that configuration file and see how we could use them. 10 00:00:58,470 --> 00:01:06,220 I'll clear all of these locations from the previous lesson create a new location for Slash inspect. 11 00:01:06,450 --> 00:01:09,210 And in this location simply return a few of these. 12 00:01:09,210 --> 00:01:17,900 Engine X variables return status 200 a string and using double quotation marks. 13 00:01:17,910 --> 00:01:21,750 We can directly embed variables into this response string. 14 00:01:22,110 --> 00:01:28,470 First one I'll add is the host variable variables being prefixed with a dollar sign. 15 00:01:28,470 --> 00:01:30,620 Add a new line character. 16 00:01:30,630 --> 00:01:40,960 You are a new line and ARGs which is the requests query string save this and reload the configuration. 17 00:01:42,640 --> 00:01:44,890 Navigate to that new location. 18 00:01:45,490 --> 00:01:46,950 Slash inspect. 19 00:01:47,990 --> 00:01:50,780 And we see each variable on its own line. 20 00:01:50,780 --> 00:01:56,150 The host which is the server I see as I'm not using the domain name and the request. 21 00:01:56,150 --> 00:01:58,530 You are I slash inspect. 22 00:01:58,550 --> 00:02:02,780 Of course we didn't pass a query string so the args variable is empty. 23 00:02:02,780 --> 00:02:12,470 But if I add query name equals Ray that's now also returned albeit in its complete string form. 24 00:02:12,470 --> 00:02:18,050 We can however use a variation of the args variable to get individual query parameters. 25 00:02:18,080 --> 00:02:20,470 I'll change this string to name. 26 00:02:21,390 --> 00:02:23,730 Argh underscore name. 27 00:02:23,940 --> 00:02:30,960 So based on the query string engine it compiles a named variable for each parameter prefixed with Arg 28 00:02:31,560 --> 00:02:33,570 save and reload this. 29 00:02:34,520 --> 00:02:38,890 Reload and this time we get the value of the name parameter. 30 00:02:38,930 --> 00:02:46,160 So already a very powerful feature set of engine X engine X also allows us to perform basic conditionals 31 00:02:46,400 --> 00:02:53,000 or if statements which most commonly will be used in conjunction with one of these variables before 32 00:02:53,000 --> 00:02:54,150 I demonstrate however. 33 00:02:54,170 --> 00:03:01,640 Note that the use of engine X conditionals inside location contexts is highly discouraged as this can 34 00:03:01,640 --> 00:03:04,030 lead to some very unexpected behaviour. 35 00:03:04,190 --> 00: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 36 00:03:09,440 --> 00:03:14,770 more on the subject I've linked to a very detailed explanation in the list and resources. 37 00:03:15,020 --> 00:03:15,430 Righto. 38 00:03:15,440 --> 00:03:21,620 Outside of this location context then I'll create a conditional which for the sake of demonstrating 39 00:03:21,930 --> 00:03:27,300 chicks are hypothetical AP Iki if with braces. 40 00:03:27,410 --> 00:03:32,640 Note the space between the F and the braces being required for this syntex to be valid. 41 00:03:32,920 --> 00:03:35,870 Argh underscore a p Iki. 42 00:03:35,880 --> 00:03:43,760 So checking the value of the API key query parameter not equal to 1 2 3 4. 43 00:03:43,820 --> 00: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 44 00:03:50,870 --> 00:03:57,020 any you are a return of foro 1 which is the unauthorized status code. 45 00:03:57,020 --> 00:03:59,600 Incorrect API key. 46 00:03:59,600 --> 00:04:00,980 Save this. 47 00:04:03,300 --> 00:04:07,740 Reload with alt that API parameter key this time just requesting the root. 48 00:04:07,740 --> 00:04:08,300 You are right. 49 00:04:08,310 --> 00:04:11,240 So their demo site and we're denied. 50 00:04:11,370 --> 00:04:15,150 As per that conditional add the API key parameter. 51 00:04:15,150 --> 00:04:22,980 However with a value of 1 2 3 4 and were served indexed update the amelle as the conditional did not 52 00:04:22,980 --> 00:04:28,860 evaluate to true image and style sheet simply being missing as the internal requests for those didn't 53 00:04:28,860 --> 00:04:31,080 include the API key parameter. 54 00:04:31,420 --> 00:04:36,960 OK as I mentioned we can also set our own variables within range and X configuration. 55 00:04:36,960 --> 00:04:43,400 I'll get rid of all this and to create a new variable we can say set the variable name. 56 00:04:43,440 --> 00:04:47,220 I'll make this weekend and the variable value. 57 00:04:47,430 --> 00:04:50,060 No so no equals sign. 58 00:04:50,070 --> 00:04:56,910 Just the standard engine X director format variables can be set to simple strings such as this example 59 00:04:57,360 --> 00:04:59,520 integers or booleans. 60 00:04:59,520 --> 00:05:06,270 True and false then for another hypothetical use case we can check if it is weakened by creating an 61 00:05:06,330 --> 00:05:11,940 if statement and using the date underscore local engine x variable. 62 00:05:11,940 --> 00:05:18,930 This variable holding an ISO date time string for the local time and instead of a simple equals or not 63 00:05:18,960 --> 00:05:20,400 equals operator. 64 00:05:20,430 --> 00:05:28,860 We can use a regular expression as with location contexts folder checking on this variable for Saturday 65 00:05:29,220 --> 00:05:30,940 or Sunday. 66 00:05:31,170 --> 00:05:36,130 In which case if this is true set weekend 2 Yes. 67 00:05:37,460 --> 00:05:40,510 So starting out we said weekend to be No. 68 00:05:40,640 --> 00: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 69 00:05:46,970 --> 00:05:48,870 of weekend to be yes. 70 00:05:49,570 --> 00:05:52,720 Change this location to is WEEKEND. 71 00:05:53,300 --> 00:05:56,490 Returning two hundred and the weekend variable. 72 00:05:56,520 --> 00:05:57,990 So yes or no. 73 00:05:58,930 --> 00:06:01,540 Save and reload the configuration. 74 00:06:03,170 --> 00:06:09,850 Navigate to that you are I is under school weekend and it being a Monday at the time of recording this 75 00:06:10,150 --> 00:06:11,540 we get no. 76 00:06:13,190 --> 00:06:16,770 Change the condition to check for Monday instead then. 77 00:06:17,670 --> 00:06:19,910 I'll rename this variable to mun. 78 00:06:21,840 --> 00:06:25,440 And said the location to is Monday. 79 00:06:26,800 --> 00:06:27,860 Reload. 80 00:06:30,290 --> 00:06:32,490 Navigate to is Monday. 81 00:06:34,630 --> 00:06:38,320 And this time we get yes as this conditional evaluator. 82 00:06:38,330 --> 00:06:44,380 True true and updated the variable to be yes in the next place and we'll use some of these variables 83 00:06:44,380 --> 00:06:46,930 to learn about rewrites and redirects.