Creating a studio theme

Published

Codepen on gold landingpen
Original Gold landingpage on Codepen.io

In this guide we will rework a Codepen into a Cradle CMS theme using the Landing Page Canvas CMS theme. The theme template is intended to be a simple to use when adding a custom code for the front page. The theme has templates for pages, blogs and articles as well as a site header and footer.

Codepen.io is an excellent place to find fun frontend code for websites, all codepens are published under MIT license and this means in short that they are free to use, modify and redistribute. The Gold Landingpage on Codepen has a simplistic and elegant look and feel, perfect for a portfolio or digital brand website.

Creating a studio theme from codepen

Steps in video

  1. Installing the Canvas CMS Theme in Themes and Publish
  2. In the code editor add the HTML from the Codepen in the index.liquid
  3. Create a CSS-file and add the CSS from the Codepen.
  4. Add modal component into theme
  5. Rework the HTML and CSS code to work with the modal component
  6. Add theme setting for background video

Install theme and add code

The theme is installed on the site with the URL from Github, in Cradle themes can be installed from any public URL pointing to a zip file. It is also possible to upload a theme-zip file from a local directory. The installed theme is published as work is done on a closed site. If working on an active site the theme can be viewed in preview mode.

The Landing Page Canvas has an completely empty index.liquid file, this is where the HTML content from the pen is added. For the CSS a new file is created and the content is added from codepen (note that you need to compile to CSS from SCSS on the codepen side). It would be possible to add the CSS in the end of the existing file as well.

Add modal component

full width navigational modal
Full width open navigation modal

The JS in the codepen is written in Babel and includes three scripts from 3-rd party CDNs which adds potential attack vectors and should be avoided.

At the same time we only need the JS for the main navigation modal and for the animations around opening it. We will use the HTML dialog element instead.

Modal component with dialog element

Components are added to the catalog components in the theme.

As the dialog was to cover the whole page max-width and max-height needed to be set to 100% on the dialog element, as the default browser styles leaves a gap otherwise and height: 100vh; will still not cover the whole height.

dialog.amodal {f
		box-shadow: var(--s);
		margin: auto;
		overscroll-behavior: contain;
		padding-top: 1rem;
		width: var(--w);
		outline:none!important;
		height: 100vh;
		max-width: 100%;
		max-height: 100%;
		background-color: #000;
}

CSS animations

The animations can be recreated with CSS animations. The line wrapper could be recreated with an animation on the width.

<div class="line-wrapper">
      <div class="line"></div>
</div>
HTML for line
.line-wrapper {
  height: 0;
  width: 150vh;
  position: absolute;
  left: calc(100% - 100vh);
  top: 0;
  transform-origin: top left;
  transform: rotate(45deg);
  animation: 0.5s linear 0s 1 normal drawnout;
}
@keyframes drawnout {
  from {
    width: 0;
  }
  to {
    width: 150vh;
  }
}
.line {
  box-shadow: 0 0 0 1px #979797;
  width: 100%;
  transform-origin: center;
  opacity: 0.6;
  margin: 0 auto;
}
CSS for line with animation

Rework navigation

settings for navigation
Theme settings for picking link-lists for navigation

Also support for adding a link lists in theme settings is included, one for the main section in the top, and a other one for the bottom footer with theme settings.

Guide on adding settings for link-lists in theme settings

Theme settings for index page

Theme settings for index page

The index page supports a background video, a title text and a button and all this is worked into theme settings for easier modifications.

Guide on adding settings for video upload in theme settings

Theme settings for colors

To be able to change colors for the index section and the navigational modal theme settings were added specifically for the objects.

    --bg-nav: #000;
    --tc-nav: #fff;
    --bg-index: #000;
    --tc-index: #fff;
    --btn-index-bg: #000;
    --btn-index-txt: #fff;
Defined variables with theme settings

Multilingual support

Translation support with the translation filter | t, in this case it is only for the button on the index page.

<a href="{{ settings.heroButton | url }}" class="hero-button btn">
	{{ 'Learn more' | t }}
</a>

More on translations and the translations filter

Final theme

The final theme can be found on Github Studio CMS theme