‫Okay.
‫So now we're going to look at using if statements within our HTML template because there are some shorthands
‫that we can use.
‫So what I want to do is change this h one or change what it says based on if we're logged in or not.
‫And obviously we don't have a login system, but we'll just use a variable.
‫So let's go up to the top and let's open up our PHP tags and close it.
‫And in here I'm just going to set a variable called is logged in.
‫And I'm going to set that to true.
‫All right.
‫And then down here if we're logged in I want to show welcome to the app.
‫If we're not I want it to say please log in.
‫So let's open up our PHP tags and we'll say if and instead of doing an, you know, an open curly brace
‫and then having the closing one down below, we can use the same type of shorthand that we did with
‫the loops.
‫So we could use just a colon like that, close it up.
‫And then where we want to end it, we can say end if.
‫Okay.
‫Just like we can do end for each or end for.
‫So now we're just going to check for is logged in.
‫And if we reload we see welcome to the app because we are logged in.
‫If we change this to false and reload we don't see anything which obviously you're not going to want.
‫So let's add an else.
‫We can say PHP else colon like that.
‫And then I'll just grab this, paste that in.
‫And then let's change the text here to please log in.
‫Reload we get please log in.
‫Change it back to true and we get.
‫Welcome to the app.
‫So you can see how we're making this dynamic.
‫Now in addition to that let's add a name.
‫Let's say name.
‫And I'm going to set that to null by default.
‫Because what I want to do is also check to see if the name is set, in addition to checking if they're
‫logged in.
‫So there's a couple ways to do this.
‫One way is to nest, which is kind of a messy solution.
‫But I'll show you that.
‫So in the if is logged in then we want to check for the name.
‫So we'll say if.
‫Let's say if is set.
‫Name.
‫So if is set name, then I want to show welcome, but I want to.
‫I want it to say their name afterwards.
‫So let's let's add the end if for this first.
‫All right.
‫And then I'll just for this H one I'll copy that.
‫Put that in here.
‫And if the name is set then let's say welcome and then their name.
‫So we'll open up our.
‫Actually we can just use the shorthand.
‫And just output the name.
‫Now, if the name isn't set.
‫So let's do a.
‫Peoples.
‫If the name is not set, then I'm just going to move this up into here and we'll say welcome to the
‫app.
‫So let's reload.
‫And we see welcome to the app because we are logged in but the name isn't set.
‫And if we're not logged in.
‫Then it's going to show.
‫Please log in if we are logged in and the name is set.
‫Then we see welcome John Doe.
‫So this looks a little messy with the nesting.
‫So we could we could make this a little bit cleaner by checking to see if they're logged in.
‫And the name is set at the same time.
‫And we can do that using the double ampersand operator and using an else if.
‫Now I'm going to get into comparison operators in the next video, but we're just going to use one here
‫just to clean this up.
‫So I'm going to leave this here while I type this out so that you can kind of compare the two.
‫So again we're going to check let's say if.
‫And we're going to check is logged in.
‫But then I'm going to say double ampersand.
‫So that's and the name is set.
‫Okay.
‫So I'm checking for both.
‫If that's true then I want to welcome the name.
‫So I'll just put that in there.
‫Then we're going to have an else if so PHP.
‫So we can do this as well.
‫Elsif.
‫Colon.
‫And then here I'm just going to check for for just logged in.
‫So if is logged in and if that's true, then we'll say we'll do the welcome to the app.
‫Okay.
‫Then we want to do PHP ls and that will be if logged in and name is not set, which in that case we
‫want to show the.
‫Please log in.
‫And then we can end.
‫And if.
‫All right.
‫So these will do the same thing.
‫If I reload you can see we get welcome John Doe if I change name.
‫To null or if I delete the variable.
‫Then it'll say welcome to the app.
‫If I change is logged in to false.
‫We get, please log in.
‫Okay.
‫So both of these do the same thing.
‫But this is a little cleaner.
‫Now, like I said in the next video, we're going to start to look at comparison and logical operators.