Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating custom templates #17

Open
github-learning-lab bot opened this issue May 19, 2020 · 3 comments
Open

Creating custom templates #17

github-learning-lab bot opened this issue May 19, 2020 · 3 comments

Comments

@github-learning-lab
Copy link

Creating custom templates

Branch: custom-template

Introduction

Stores are made up of several different pages, each with a specific content and layout. When creating a store from scratch in VTEX IO, some default pages with preset URLs are already available. Below, we have a list of some of these default pages:

  • store.home �(Home page)
  • store.product (Product page)
  • store.search (Search Results page)
  • store.account (Client Account page)
  • store.login (Login page)
  • store.orderplaced (Order Placed page)

But it's also possible for you to create a custom landing page. In this case, you should create a new URL and specific content to display to users that access this path.

Creating a Landing Page

Just a few steps a needed to create a custom landing page:

  1. Create a new template in your store's theme
  2. Create a new path to access this template

Template

A template defines the page layout. However, if you want to create a custom page, you will also need to create a new template in your theme.

Let's imagine that your wanted to created a simple page containing information about your store. Inside the blocks folder, you can create a file that would contain the following code, declaring a new template for a custom page,

{
 "store.custom#{templatename}": {
     "blocks": [
     ]
  }
}

where {templateName} must be replaced with the template's identifying name.

Then, you should fill in the code with the components needed to create the layout. Below we can an example of such implementation:

{
 "store.custom#{templatename}": {
   "blocks": [
     "flex-layout.row#about-us"
   ]
 },
 "flex-layout.row#about-us": {
   "children": [
     "image#about-us",
     "flex-layout.col#text-about-us"
   ]
 },
 "flex-layout.col#text-about-us": {
   "children": [
     "rich-text#about-title",
     "rich-text#about-content"
   ],
       "props": {
     "preventVerticalStretch": true
   }
 },
"rich-text#about-title": {
   "props": {
     "text":
     "# About FlatFlat"
   }
 },
 "rich-text#about-content": {
   "props": {
     "text":
     " FlatFlat is an electronics store with a long standing tradition for creating modern and vintage items. Out objective is to create home appliances that make your house stand out, no matter your style. Merely 2 months old, we're already the store with the most beautiful products among all VTEX stores. We are currently building our site with the aim of giving our customers an unforgetable experience with our brand!"
   }
 },
 "image#about-us": {
   "props": {
     "src": "https://appliancetheme.vteximg.com.br/arquivos/cozinha-about-us.png",
     "maxHeight": "600px"
   }
 }
}

Path

Now that a new template with the page layout has been defined in the store theme's code, the next step is to establish the page's page that would lead to this layout.

We must create a routes.json file in your theme's store folder. Afterwards, insert the code below,

{
  "store.custom#about-us": {
    "path": "/{URL}"
  }
}

where {URL} is the name of the desired path.

Activity

Let's create a page containing information about your store, as in the example below:

  1. In the blocks folder, create a file called about-us.jsonc;
  2. Declare a store.custom#about-us template in this file;
  3. Include a "flex-layout.row#about-us" block in this template;
  4. After declaring flex-layout.row, use the code in example given above to complete the page layout;
  5. In the store folder, create a file called routes.json;
  6. In this file, declare an /about-us path;
  7. Once the code is linked, access {workspace}--appliancetheme.myvtex.com/about-us to see your new landing page.

If you're still unsure as to how to send your answers, click here.

@github-learning-lab
Copy link
Author

You have successfully completed this step!

Go to the next step!

@vtex-course-hub
Copy link

You did great! 😁

Results

✅✅✅✅✅

Tests

✅ Getting the file
✅ Declare a store.custom#about-us template in your about-us.jsonc file
✅ Add a flex-layout.row#about-us to your template
✅ Use the sample code provided in the instructions for this step to complete the layout
✅ Create a routes.jsonc file and declare a /about-us path and check your workspace at {workspace}--appliancetheme.myvtex.com/about-us to see the new page :)

@vtex-course-hub
Copy link

Oopsie, something went wrong 😿

Results

✅✅✅❌✅

Tests

✅ Getting the file
✅ Declare a store.custom#about-us template in your about-us.jsonc file
✅ Add a flex-layout.row#about-us to your template
❌ Your code did not match the sample one provided in the instructions for this step
✅ Create a routes.jsonc file and declare a /about-us path and check your workspace at {workspace}--appliancetheme.myvtex.com/about-us to see the new page :)

Try again 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants