How to use If Statements in BigCommerce Stencil

Apr, 13 2022How to use If Statements in BigCommerce Stencil

BigCommerce & If Statements

Are you venturing into custom theme develpment in BigCommerce with Stencil?

Knowing how to use IF STATEMENTS is a necessity. This quick video will show you the process. If you haven't already watched my in-depth video on Local Stencil Theme Development, you can check it out here.

Also, please share with me the topics in BigCommerce that you'd like to see videos on. 🤩

Video Transcript

Hey guys, are you guys trying to figure out how to use if statements or what the heck if statements are in big commerce, you're in luck. In this video I'm going to show you guys. And before we get started, my name is Kal, I'm a developer store owner and I run the E commerce growth community for store owners just like you, I'll have a link at the end. And you know, each week I post more videos about e commerce. So if you find this one helpful, subscribe, hit the bell, and you can see more.

Okay, I'm going to share my screen. And we're going to talk about if statements on big commerce. So first of all, in this storefront, I have a theme to customize a theme, you do have to customize a copy. So if you're working on an original theme, make a copy, make that active, and then click edit theme files to get into the stencil editor.

Now, if statements are the basis of programming, so, you know, you can be very basic, you can be very advanced, depending on what you want, you can have nested IF statements, I'm just gonna show you guys the basics, about how it works and how the syntax is on Bigcommerce.

So to do this demo, we're gonna go into my theme, we're gonna call it templates, components common, and then header, just to give us a place to show off some if statement goodies.

Now, what an if statement is, is it says, If this is true, then do this thing. And you can also say, or else do this other thing. And the way that this works instance, oh, code is you say, curly bracket, curly bracket pound, if this is true, and then we're going to close that off, and then we're going to put a slash F at the end of it.

So the pound F opens the statement, the slash F close it. And so anything, anything that's in the middle is only going to happen if this one condition is true. And we can, let's let's just do that first. So let's, we're going to say, we're going to say here on this store, that if the if the title of the category is apparel, then execute the code, right? And so let's just say here.

Category Name, Category Name, okay. So if category name back to my code. If the category name equals oops, apparel, then we're going to say this is the apparel category, we're just going to put that onto the page, right below the header in a paragraph tag was a second update or a couple seconds, we're going to refresh the front end. And you can see that it does, it did output our sentence here that this is the apparel category and if we click over to a different page, like campsite, because the the title of this page isn't campsite, and then it doesn't show that so it only shows that if we have correctly identified the apparel category.

Now going back to our if statement, there's one other thing that you can do is you could put an else in here. So we can say oops, fat fingered it. So curly bracket, curly bracket else, curly bracket, curly bracket. belts, this is not the apparel category. Right? So if it is apparel, then it's gonna say this and if it's not, then we're gonna say this

All right, go back to the front end. So it still says this is the apparel category here. On the apparel category, and on something else, it says, This is not the apparel category. Now we can, you know, I'm obviously just targeting one thing by saying if this is apparel that do this, but you could also say like, if the page type is category, then say this thing, and then that would basically execute on anything that matches the category template. So that would be all of the categories, but not the product pages, not the homepage, whatnot.

You can, you know, one thing that we do a lot is on product pages, we say, if there is a custom field that is this, then do this sort of thing. And so you can see, like, you know, once you get the basics of the if statement, you know, it's, you know, it's, it's very, it's very broad, what you can do, and this is, you know, the basic category structure.

So, if blank is true, this right here, then do this, else do that. And that's about it. So, you know, that's the basics might, my goal here was just to show you guys the basics. You know, I'll do lots of other videos showing you very specific things that you can do with this. But, you know, you got to start somewhere. And so if you guys are just getting started in big commerce, this is pretty, pretty nifty to use.

So pound, if, you know, blank is true, adults do this sort of thing. And that's about it. So hopefully, you guys found this helpful. Be sure to join our community and join ecommerce If you guys need a developer come to us at Epic design labs, there's so much stuff that we can do, literally just scratching the surface with if statements is the basic building block of a PHP programming and, man, it's it's crazy, all the stuff that we could do with it. Be sure to give me a comment let me know what you guys are gonna do.

Let me know what you guys are stuck on. So, you know, every week I want to make more videos for you guys, and, you know, just help you guys more and more get farther with big commerce.

So let me know what you guys are stuck on and maybe that'll be my next video. Thanks so much and I'll see you next time.