Skip to content

Creating a static photography portfolio landing site with HydePHP

Posted by author in the category "tutorials"

Introduction

HydePHP is a new framework for rapidly building static websites using tools you may already know from popular frameworks like Laravel.

In this blog post, we'll be recreating this simple photography portfolio site using HydePHP and Markdown. No coding is needed!

You can find the source code on GitHub and the live demo here.

Tip: This tutorial is also avaliable as a free video lesson on YouTube!

Screenshot of the site we'll be recreating

Prerequisites

This post is aimed at beginners and will guide you through both the installation and basic usage of HydePHP. You don't need to know PHP to get started, though you should have it installed on your system as well as Composer is required to download and run HydePHP.

HydePHP is a command-line application, however, it's very easy to use, as long as you've ever seen a terminal in your life, you can follow right along!

Installation

HydePHP is installed on a per-project basis using Composer, a PHP package manager. If you don't have Composer installed, you can download it from getcomposer.org.

Once you have Composer installed, you can create a new HydePHP project by running the following command in your terminal or command prompt:

1composer create-project hyde/hyde --stability dev

Since HydePHP is still in development, you'll need to specify the --stability dev flag to install the latest version.

Once you run the command, Composer will download HydePHP and all of its dependencies. This may take a few seconds up to a few minutes depending on your internet connection. Once it's done, you'll see a new directory called hyde show up in the directory you ran the command in.

Screenshot of the command and output

You can now navigate into the hyde directory using the command line with the cd (change-directory) command:

1cd hyde

Now that you're in the hyde directory, you have a fully functional HydePHP project. We interact with the software through the HydeCLI, which is accessed by running php hyde followed by a command name. Make sure to run this command from within the hyde directory which we just navigated into.

To show the welcome screen with a list of the available commands, run the following command:

1php hyde list

The list command

If you are unsure what a command does, you can always add the --help flag to any command to get more information about it. For example:

1php hyde new --help

The help flag

You can also always refer to the online HydePHP CLI documentation for more information.

Running the Development Server

HydePHP comes with a built-in development server that you can use to preview your site as you work on it. To start the development server, run the following command:

1php hyde serve

This will start a local web server that will compile your site on the fly. You can access the site by visiting http://localhost:8080 in your browser. Once you visit this link, you should see the HydePHP welcome screen.

The default welcome page is compiled from a Blade file you may recognize from Laravel. The source page is stored in the _pages/ directory as index.blade.php. When we compile our site later on, this file will be compiled to index.html in the _site/ directory.

Default welcome page

Creating our First Page

The welcome page is nice and all, but I promised we'd be creating a photography portfolio site, so let's get to it! Since this is a simple site, we'll be using Markdown to create our pages. Markdown is a simple markup language that is easy to read and write. It's also fully supported by HydePHP, making it perfect for what we want to do. For when you want something more complex or dynamic, Laravel Blade is also supported.

Since we'll be replacing the default page, let's first remove it. You can delete the file directly using your app of choice, like Finder or Windows Explorer. But since we're already in the terminal, let's use the rm (remove) command to delete the file:

1rm _pages/index.blade.php

Now, to creating our page. Since everything in HydePHP is file-based, we can just create a new file in the _pages/ directory and call it index.md. But Hyde offers a neat command to create new pages for us, so let's use that instead:

1php hyde make:page index

This command will create the _pages/index.md file for us. Now, let's open the file in your favourite text editor and take a look!

1---
2title: index
3---
4 
5# index

As you can see, a special section at the top of the file called the "front-matter" is used to define the page's title. The front matter is written in YAML, a simple markup language that used by HydePHP to define metadata.

The front matter is followed by the page's content, which is written in Markdown. Using front matter is optional, as HydePHP can infer many types of metadata, like page titles, from other sources like headings and filenames. But if you want to override these inferred values, you can do so by defining them in the front matter as is shown here.

Now that we have our page, let's add some content. I have already written some content for this site, so I'll just copy and paste it into the file. If you're following along yourself, simply copy the following into the file:

1## Hey there, I'm Jane Doe!
2 
3# Freelance photographer
4 
5![Jane Doe](media/photographer.jpg)
6 
7## About
8 
9This is a demo website built with [HydePHP](https://hydephp.com/), a free and open-source static site generator. This entire site is built using just Markdown text that is transformed into a fast and secure website that can be published anywhere.
10 
11Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec euismod, nisl eget consectetur consectetur, nisi nisl aliquet nisi, euismod consectetur nisi nisi euismod nisi.
12 
13## Gallery
14 
15![Austria](media/austria.jpg)
16![Boat](media/boat.jpg)
17![Croatia](media/croatia.jpg)
18![Fireworks](media/fireworks.jpg)
19![Hallstatt](media/hallstatt.jpg)
20![Lemonade](media/lemonade.jpg)
21{.gallery}
22 
23 
24## Contact
25 
26- Phone: +1 (123) 456-7890
27- Email: jane.doe@example.com
28- Address: 123 Main St, Anytown, CA 12345

As you can see, I removed the front matter, letting Hyde infer it automatically from the heading. I also added some images to the page, as well as a CSS class that we can use to add some styles to the images later on.

If you now refresh the page in your browser, you should see the page we just created. But it's of course missing the images, so let's add them!

Added page has broken images

Adding Images

Adding images to HydePHP sites is easy. Just drop them inside the _media/ directory. When you compile your site, HydePHP will automatically copy all the files in this directory to the _site/media/ directory. This means that you can reference your images using relative paths, like media/photographer.jpg in the example above.

If you are following along, you can download the demo images from the GitHub repository.

Screenshot of Windows Explorer in the _media directory

Now if you refresh the page in your browser, you should see the images we just added. But the images are a bit too big, so let's fix that!

Images on the website are too large

Adding Basic Styles

We added a CSS class before called .gallery, so let's add some styles to that class.

If you want to add a lot of styles, you may want to take a look at the Compiling assets documentation, but for this demo, we just want to add a single class, so we'll use a shortcut.

HydePHP comes with a complete frontend with components to create everything from blog posts to documentation sites. These templates are built with TailwindCSS. To make things easier for you, a pre-compiled and minified version of all the Tailwind classes needed for the built-in templates is included in the base installation. You'll find them in the app.css file in the _media/ directory.

Generally, you shouldn't edit compiled files, but since we're just adding a single class, it's fine. Just make sure to add the class again if you ever update HydePHP.

With that out of the way, open the file in your favorite text editor and add the following to the bottom of the file:

1.gallery {
2 display: flex;
3 flex-wrap: wrap;
4 justify-content: space-between;
5}
6 
7.gallery img {
8 max-width: 65vw;
9 width: 44ch;
10 margin: 3ch 2ch;
11}

Now if you refresh the page in your browser, you should see the images are now smaller and fit nicely on the page.

Images are now in a neat grid

Compiling the Site

Now that we have our site, let's compile it. We do this by running the hyde build command:

1php hyde build

This will take all of our source content and compile it into a static site that can be published anywhere. The compiled site will be placed in the _site/ directory.

Screenshot of terminal output

Publishing the Site

Static sites are super easy to publish. You can publish them anywhere you can host a website, like GitHub Pages, Netlify, and traditional shared hosting, just to name a few. That's one of the reasons why I love static sites so much! However, that's outside the scope of this tutorial, but do check out the Deployment documentation for more information.

In short though, just drop the contents of the _site/ directory into the root/public directory of your web server and you're done!

The compiled site files

What's Next?

Now that we have a basic site, the world is yours! There are plenty of customizations we can do, for example adding some links to the navigation, or adding a blog. But that's for another tutorial. For now, I hope you enjoyed this tutorial and learned something new.

If you have any questions, feel free to ask them in the HydePHP Discord server or open an issue on GitHub.

You can also check out the HydePHP documentation for more information on how to use HydePHP. You can always also reach out to me on Twitter, @CodeWithCaen.

HydePHP.com


Syntax highlighting by Torchlight.dev

End of article