New Colocation Homepage with Statamic

New Colocation Homepage with Statamic

The goal is to recreate the new Colocation Homepage in / with Statamic exactly as it is given in Zeplin: https://zpl.io/30xPRQA

Zeplin makes such recreation a easier since you can see the sizes of the different elements and even their HTML and CSS code snippets with an extension you can also see the Tailwind CSS version of the CSS. This makes a big difference because before for the recreation it was mostly guess work and trial & error.

I firstly went about creating the necessary elements (pages, blueprints, etc.) in Statamic so when i then program the actual code i can directly see if it works. I wanted to create a new Collection so its more separated from my already existing parts but as i did so i encountered a few issues. The collection didn’t seem works like i intended which after some fixing attempts and it still not working i decided to go for a different way since its not necessary for it to be its own collection and therefor didn’t want to waste much time on something marginal.

After my failed collection attempt i just created a new entry called “Colocation” in my existing “Pages” collection. That worked as intended, now the next part is the main part which is the blueprint for the Colocation page. Now i decided to create the whole blueprint inside a single replicator field (which i called “Page Sections”). I opted for that solution because the page is rather big and would require a lot of different fields that it can look quite cluttered and overwhelming. Inside a replicator field you can add different sections (or called Sets in Statamic) this allows you to split up well different parts / sections of the website. Now i decided to split the first half of the website (since that is the current task) into 4 parts:

Information:

Features:

Offers:

Video:

Here’s how the 4 sections look like in Statamic:

Now i mentioned that this makes it less cluttered and overwhelming this is because now when you edit the page there aren’t dozens of fields displayed but a single plus button. There you can add the different sections one after another. Another advantage is that with this current set up you can decide if you want all the different sections or not. In this instance it is not required and in the code later then you would need to program it a bit differently if you desire that but its still a nice bonus that one could use if desired.

Now one could also argue that since you can manually add the different sections and if the code isn’t made to handle a missing sections that it could then break the code. That is correct in such instance the code would / could break but there are different ways you can go about preventing that. For example you could make the code fine to handle such cases or you could make the fields required which then in turn “forces” you to add all the different sections. In this particular case since the goal is to recreate the given website all sections will be used even if not required so (at least for the moment) this issue is negatable.

The first thing i did in the code is create all the necessary folders & files. These were the following:

  • resources/views -> a new folder called “google_ads”
  • resources/views/google_ads -> a new file called “show.antlers.html”
  • resources/views -> a new folder called “sections”
  • resources/views/sections -> 4 files called:
    • “information.antlers.html”
    • “features.antlers.html”
    • “offers.antlers.html”
    • “video.antlers.html”

So in the 4 files inside the sections folder are the sets as defined in Statamic. As for the show file that is for displaying to whole page.
The first step was just to create some placeholder code that contains just the required to display all the elements that are given in the blueprint in a reasonably visually pleasing & understanding manner for a test. After that i checked if everything loaded correctly and if its able to find everything. During this part i encountered the first hurdle because there were multiple parts which didn’t want to work and the main one was that it didn’t show the content at all. I was rather confused since the naming’s of the Statamic blueprint names/slugs were correct same as my antlers syntax. So i tried to figure out why it wasn’t working by checking the syntax multiple times trying different methods and all but after a short break i had a hunch that it there might be a name conflict so that antlers doesn’t know which of the collection or slugs to pick so i created a copy of the whole Statamic site (concerning the Colocation Landing page) with that in mind and that indeed worked which confirmed my hunch.
After that was done and I adjusted the code with the now correct corresponding names / slugs i was able to display the things given from Statamic. There were still a few minor issues about an element not displaying but those were pretty easy to fix.

Now that the connection between the code and Statamic is working properly im able to dedicate my attention towards the actual design of the page.
I moved from the top of the page downward, meaning that i firstly completed the “information” set then the “features” set after which the “offers” set and then finally the “video” set. The reason i choose to go in that order (since it is grouped into smaller sections the order wouldn’t much matter) is for 2 reason: The first reason is that its the order in which i created the sets in Statamic and i like to keep things consistent, The second reason is that it’s the chronological order of the page, so it felt the most “natural”. I choose to follow my “want” because it generally makes things easier if your able to do something in a manner which is appealing to oneself.

Zeplin made the design optimisation a lot simpler since im able to look at the color hex codes or certain attributes & values compared to having an image which made a lot less reliant on trial & error. It was unusual to work with a tool like that since it was my first time that i did so but not much was required to at least make use of Zeplin for the moment since its a pretty understandable design. During a few instances i asked Manuel for assistance and he was able to show me some tips of what Zeplin can do and how to utilize it.

Now after i was done with the design of the different sets it looked alright it was still far from perfect but there was a clear resemblance of what i was given. The main thing that i struggled with was the background at the start of the page. It was rather fragile code since if i changed something it could break quite easily which lead to quite a bit of frustration because even if i changed a part of the code that didn’t have any direct relation to the background or that part of the background it would still affect it at times. I racked my brain a good bit trying to get it to look accordingly but in the end nothing i tried worked well or well not enough. Now after my vacation after i took another good look at the design in Zeplin and noticed that its not different elements positioned after one another but its layered. Now with that realization i also changed the way which i approached it in the code. In the past the background element were in their respective set but now i moved them to the “show.antlers.html” file. Now after a few different tries i was able to make it work.

PHP
<div class="pointer-events-none absolute inset-0 z-[1]">
            <div class="absolute inset-x-0 top-0 h-[2110px] bg-[#0d0e1a] md:h-[1710px] lg:h-[1390px]"></div>
            <div class="absolute left-1/2 top-[1980px] h-[250px] w-[140%] -translate-x-1/2 rounded-[100%] bg-[#0d0e1a] md:top-[1580px] lg:top-[1240px]"></div>

            {{ page_selections }}
                {{ if type == "information" }}
                    <div class="absolute inset-x-0 top-[59px] h-[640px] overflow-hidden md:h-[720px] lg:h-[768px]">
                        <img
                            src="{{ glide:background_image }}"
                            alt="{{ background_image:alt }}"
                            class="h-full w-full object-fill opacity-100"
                        >
                    </div>
                {{ /if }}
            {{ /page_selections }}

            <img
                src="/assets/blur-angebote-vdc-colo@3x.webp"
                alt=""
                aria-hidden="true"
                class="absolute left-1/2 top-[1650px] h-[520px] w-[900px] max-w-[calc(100%-2rem)] -translate-x-1/2 opacity-95 object-fill blur-3xl mix-blend-screen md:top-[1320px] md:h-[560px] md:w-[1100px] lg:top-[1020px] lg:h-[628px] lg:w-[1294px] lg:max-w-[calc(100%-3rem)] lg:-translate-x-[48%]"
                style="mask-image: radial-gradient(ellipse at center, #000 0%, #000 46%, transparent 76%), linear-gradient(180deg, transparent 0%, #000 18%, #000 82%, transparent 100%); mask-composite: intersect; -webkit-mask-image: radial-gradient(ellipse at center, #000 0%, #000 46%, transparent 76%), linear-gradient(180deg, transparent 0%, #000 18%, #000 82%, transparent 100%); -webkit-mask-composite: source-in;"
            >
        </div>

Now the general layout of the background looked pretty well but i still had 2 issues. The first was the curve at the bottom and the second is the gradient design (the blue / purple glowing spots behind the offers). I tried a bunch of different things and gradient but in the end nothing worked as i intended. I then asked Manuel for advice and he was able to help me. For the first issue it was that it was a separate element form the existing black background and that its actually wider than the actual screen. The second issue was that its not a gradient or well not as you would normally see but an image which is masked and altered. So he showed me where i can acquire the needed image for the colocation page, which as it turned out was another page in Zeplin. Now with said knowledge in mind i was able to complete the two elements. All that was left now was to optimize 2 elements (mainly the image / gradient). The last thing i did was to implement mobile versions for smaller screens (phone & tablet).
There are still differences between what is given in Zeplin and what i created but some are currently unavoidable since for example the icons are difference (since i didn’t use pro), the font may differ as well or some other minor differences but if looked at with an eye shut then it looks basically the same. Here’s what the page looks like:

For the second part of the website it was more or less the same. Create new “Sets” in the blueprint as required and then add the necessary / desired Fields. The only thing that was special is that the “Features” (the original features not the set i created for this website. The small elements with an red-pinkish icon and a text) were a global but since i needed them here as well and in the close future again i had to recreate it as a fieldset so i can use it in other blueprints. Here’s a reference image:

After that i just added the needed files in the codebase for the newly created sets. For some, like the features (now called “product_features” so ones is able to differentiate them) or the “autoplay_video” i was able to use existing code since its the same or almost the same. So the only ones i needed to create from a (mostly) blank slate are the “contact.antlers.html” amd tje “reviewer_comment” files. Those were somewhat simple since i had some references i could use which utilized a similar base. So things weren’t all that difficult.
The element i had the most difficulty implementing is the “autoplay_video” one since its a video that auto plays and loops. Now i haven’t done that ever or well at least in a long time so i had to quickly search for some information on said matter on how to implement something like that. After some short research i had what i needed and programmed it accordingly but the block where the video should’ve been was just empty as if nothing at all is there.

After a bit of trials & error and some more research it turns out that i didn’t have to call the uploaded file (from Statamic) directly but the url of said file. After that it worked nicely.

Tags: