OK, let's change things up a little bit and pass some data to templates and organize things in a slightly
more sophisticated fashion.
Pretty easy right now.
It's going to get a little more complex as time goes on.
For the moment, this will suffice.
So right now, I have everything in one file except for my templates.
All of my go code exists in Main Dutko.
And as you might expect, this will probably get more complex over time.
And having everything stuck into one file, probably not a great idea.
So I'm going to come over here to the root level of my directory and create a new go file and I'm going
to call that handlers Dargo.
And as you might expect, I'm going to put all of my handlers into this file.
So let's go back to Main.
Don't go and find these handlers, including rendered template, and I'll cut them out of here.
And when I do, it says that my e-mail template is no longer being used and I can just reformat or manually
delete that.
And now I have I have a very simple, straightforward mango and is pointing to two functions which don't
exist because I just cut them out of this file.
So I'll just put them in here instead.
And it will my ID automatically import these things.
If yours doesn't, you have to put in this import statement.
But everything is in here.
So the one thing that's missing is goaland seems to have difficulty discovering what template we're
talking about.
So I'll just retype template parts files and then delete the extra text and then we'll add the import
for me.
All right.
So and I've got to get rid of this there.
So now I have two files and everything seems to be pretty much the same.
My my main should have no errors and it doesn't my handlers has no errors and it doesn't.
And if I try to run this application by going to my terminal window and doing what I did before, go,
run Maeng go.
It's not going to work and it's not going to work because it says, hey, in your mean go line 12,
I don't know what home is.
I don't know what a boat is.
That's because we're just trying to compile if I use this command, go, run, mean go.
It's just trying to compile mango.
In fact I want it to compile all of the go directories.
So I'm going to change that to say go, run, star, dot, go.
And now when I run it, it should work beautifully.
And if I go to my browser window and refresh there it is.
Perfect.
OK, so that's the first step is just to move things into separate files.
And logically you should try to make functions in a given file all related to the same thing you're
trying to accomplish.
So in my main main goal, mean don't go file, all I'm doing is setting up my application.
This will get more complex as time goes on.
But for now, this is sufficient.
In my handler's file, I'm just doing my handlers, except I have this render templates.
If I wanted to, I could actually cut this out of here, create a new file under Hello World.
I do go file called Render Ago and paste that in.
And again, I have to tell it about HTML templates.
So at this time I'll just go template HTML.
HTML template is the way around HTML template.
Here we go and go back to handlers and it deletes the things from my import.
So if yours doesn't, you need to manually delete those to the remote no longer being used and now it's
very clean.
Now I have three files.
Handlers are just handlers.
Main is just my main main function and render just renders templates so I can now run the same thing
and it will compile all three files.
Go run Stadt, go compiles, render girl mango and handlers dutko and it should still work.
Let's just verify that it does.
Absolutely.
Now this is a pretty ugly page and I'm going to make it a little bit prettier and I want to do that
by using bootstrap a very, very popular siestas framework.
And you get there by going to get bootstrap dotcom.
And I want to get started and I'm going to very quickly just use this link here, which copies the bootstrap
success, which is going to store my Web pages, and I'm going to go back and put this in my template.
So let's go to templates and go to the home page.
And I have to put this in the head section, so I'll paste it in and just to format it, I will automatically
format things to put it so you can see it all on one screen and I'll do the same thing on the about
page.
And right away you should start thinking, well, this seems odd.
Why do I have to have this information in two places?
Can I just put it in one and have all of my templates use that?
Yes.
In fact, you can and will be doing that shortly.
But right now, let's just go back and see what that did to that change anything.
So go back to my Web browser and reload this page.
Will it change?
The font doesn't look great, though.
It's all jammed up in the left hand corner.
What we can put a little bit of styling in here just to make it look a little bit better.
And we'll be doing more of this as time goes on.
But I'll just give you the very basics right now in order to make my homepage look a little bit better.
I don't just stick these tags, the header tag in the paragraph, tag in the body tag.
They should be wrapped in something.
And again, I'm using Emet just to save some typing.
But the very first thing you need to do is wrap your body content in a div with the class of container.
Oops, there we go.
And inside of that you have to have a row a div with a class of row and inside of that you have one
or more columns.
I'm just going to have one column for right now, so I'll put div class of call and Emet helpfully types
that all out for me and then I grab these things and put them in those three nested device and when
I go back and reload the homepage that's a little bit better.
OK, it's still too close to the top.
Maybe I want to picture up there, but right now things are starting to look a little bit cleaner.
And of course I can do the same thing in my about page so I can copy all of that.
Go to my about page and I will just put this in here and cut this and put this in here.
And I see a missing a closing body tag.
I probably should have that and format the whole thing.
And now when I go to about slash about that should have the same kind of styling and it does.
All right.
So what we've done so far, it's just a clean things up a little bit, make things a little bit more
straightforward now.
There's a lot more we can do and a lot more we will do.
Let's think about, first of all, how are we going to make this content, all of this stuff that doesn't
change from page to page, all of this head section, including the body, all of this is the same in
every page and so is the closing body tag and the closing HTML tag.
Well, we can actually do that using templates, using the template system built in to go by establishing
a layout and then having all of the pages that are going to use that layout, basically import that.
So we'll do that in the next lecture.
It's very straightforward and then we'll start passing some data to these templates.
That's enough for now.