Dukaan Themes
  • Introduction to Dukaan Themes
  • Building your own custom theme
  • Getting the basics right
  • Making your first edit
  • Theme folder structure
  • How does it all work?
  • Nunjucks Templating Language
  • Basic code editing
    • Adding the HTML
    • Adding the CSS
    • Adding the Javascript
    • Adding Nunjucks
  • Customising Dukaan Templates
  • Dukaan Data
  • Advance code editing
    • Customising core functionality
  • Dukaan Functions
  • Integrating Dukaan Plugins
    • Wishlist plugin
    • Countdown timer plugin
    • Product scarcity plugin
  • Testing and Deploying Your Theme
  • Code Snippets
    • Changing text of Add to bag button
    • Adding shadow to product cards
    • Adding auto-scrolling text in homepage
Powered by GitBook
On this page

Was this helpful?

  1. Basic code editing

Adding the HTML

✍️ Objective - To display categories in homepage

Open the layout.html file

This is how a bare minimum layout.html file would look like, it has some code which is required for a theme to function properly, avoid removing any of this code.

<!-- layout.html -->

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible"
          content="IE=edge"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    {% include './../../dukaan/common/theme-fonts.html' %}
    {{ 'splide.min.css' | css | static }}
    {{ 'layout.css' | css | static }}
    {{ 'styles.css' | css | static }}
    {% include './../../dukaan/common/seo_tags/commonSeoTags.html' %}
    {% include './../../dukaan/common/theme-colors.html' %}
    {% block head %}
    {% endblock head %}
    {{ 'head' | DukaanBlocks }}
  </head>
  {% include './../../dukaan/common/spinner-loader.html' %}
  <body class="flex d-column">
    {% include './../../dukaan/common/hellobar.html' %}
    <main class="flex flex-1 d-column">
      {% block content %}
      {% endblock content %}
    </main>
    {% include '../../dukaan/common/bxgy-sticky-footer.html' %}
    {% include '../../dukaan/common/store-open-sticky.html' %}
    {% block postfooter %}
    {% endblock postfooter %}
    {{ 'footer' | DukaanBlocks }}
    {% include './product-variant-templates.html' %}
    {{ 'variant-utils.js' | js | static }}
    {{ 'dukaan-utils.js' | js | static }}
    {{ 'layout.js' | js | static }}
    {{ 'dukaan-coupons.js' | js | static({ defer: true }) }}
    {{ 'dukaan-offers.js' | js | static({ defer: true }) }}
    {{ 'axios.min.js' | js | static({ defer: true }) }}
    {{ 'splide.min.js' | js | static }}
    {{ 'common-components.css' | css | static }}
    {% include './../../dukaan/common/auth.html' %}
    {% include '../../dukaan/common/multilanguage.html' %}
    {% include './../../dukaan/common/common-scripts.html' %}
    {% include '../../dukaan/common/snackbar.html' %}
    {% block script %}
    {% endblock script %}
  </body>
</html>

If we check now, our site would be completely blank. Now, we will try to display a dummy category.

We will display a category image and category name, go ahead and paste this code inside the body tag.

<div class="container">
    <div class="category-card">
      <a href="#" class="category-link">
        <div class="category-image-wrapper">
          <img width="300" height="300" src="https://i.imgur.com/ordhK4e.jpg" alt="Category 1" class="category-image">
        </div>
        <div class="category-name">Category 1</div>
      </a>
    </div>
  </div>

This code snippet creates a simple HTML structure to display a category card within a container. The category card includes an image and the category name, for now we have hardcoded a dummy image and category name, both wrapped within a hyperlink element for navigation purposes.

If you save & preview the changes, you'd see something like this

Let's try to add some more dummy categories, the updated code would be

<div class="container">
    <div class="category-card">
      <a href="#" class="category-link">
        <div class="category-image-wrapper">
          <img width="300" height="300" src="https://i.imgur.com/ordhK4e.jpg" alt="Category 1" class="category-image">
        </div>
        <div class="category-name">Category 1</div>
      </a>
    </div>
    <div class="category-card">
      <a href="#" class="category-link">
        <div class="category-image-wrapper">
          <img width="300" height="300" src="https://i.imgur.com/ordhK4e.jpg" alt="Category 1" class="category-image">
        </div>
        <div class="category-name">Category 2</div>
      </a>
    </div>
    <div class="category-card">
      <a href="#" class="category-link">
        <div class="category-image-wrapper">
          <img width="300" height="300" src="https://i.imgur.com/ordhK4e.jpg" alt="Category 1" class="category-image">
        </div>
        <div class="category-name">Category 3</div>
      </a>
    </div>
  </div>

This is how our site looks now

Now that we can display dummy data with HTML its time to flare up the tags by spicing it up with some CSS in the next chapter.

For reference - The contents of layout.html file after the above changes
<!-- layout.html -->

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible"
          content="IE=edge"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    {% include './../../dukaan/common/theme-fonts.html' %}
    {{ 'splide.min.css' | css | static }}
    {{ 'layout.css' | css | static }}
    {{ 'styles.css' | css | static }}
    {% include './../../dukaan/common/seo_tags/commonSeoTags.html' %}
    {% include './../../dukaan/common/theme-colors.html' %}
    {% block head %}
    {% endblock head %}
    {{ 'head' | DukaanBlocks }}
  </head>
  {% include './../../dukaan/common/spinner-loader.html' %}
  <body class="flex d-column">
    {% include './../../dukaan/common/hellobar.html' %}
    <main class="flex flex-1 d-column">
        <div class="container">
        <div class="category-card">
      <a href="#" class="category-link">
        <div class="category-image-wrapper">
          <img src="https://i.imgur.com/ordhK4e.jpg" alt="Category 1" class="category-image">
        </div>
        <div class="category-name">Category 1</div>
      </a>
    </div>
    <div class="category-card">
      <a href="#" class="category-link">
        <div class="category-image-wrapper">
          <img src="https://i.imgur.com/ordhK4e.jpg" alt="Category 1" class="category-image">
        </div>
        <div class="category-name">Category 2</div>
      </a>
    </div>
    <div class="category-card">
      <a href="#" class="category-link">
        <div class="category-image-wrapper">
          <img src="https://i.imgur.com/ordhK4e.jpg" alt="Category 1" class="category-image">
        </div>
        <div class="category-name">Category 3</div>
      </a>
    </div>
      </div>
      {% block content %}
      {% endblock content %}
    </main>
    {% include '../../dukaan/common/bxgy-sticky-footer.html' %}
    {% include '../../dukaan/common/store-open-sticky.html' %}
    {% block postfooter %}
    {% endblock postfooter %}
    {{ 'footer' | DukaanBlocks }}
    {% include './product-variant-templates.html' %}
    {{ 'variant-utils.js' | js | static }}
    {{ 'dukaan-utils.js' | js | static }}
    {{ 'layout.js' | js | static }}
    {{ 'dukaan-coupons.js' | js | static({ defer: true }) }}
    {{ 'dukaan-offers.js' | js | static({ defer: true }) }}
    {{ 'axios.min.js' | js | static({ defer: true }) }}
    {{ 'splide.min.js' | js | static }}
    {{ 'common-components.css' | css | static }}
    {% include './../../dukaan/common/auth.html' %}
    {% include '../../dukaan/common/multilanguage.html' %}
    {% include './../../dukaan/common/common-scripts.html' %}
    {% include '../../dukaan/common/snackbar.html' %}
    {% block script %}
    {% endblock script %}
  </body>
</html>
PreviousBasic code editingNextAdding the CSS

Last updated 2 years ago

Was this helpful?