How to make a unique top bar for a landingpage

Hello there

I’m creating a landing page using a product template. The header and footer are already hidden on this page. Now I’d like to copy the top bar into the template, but unfortunately Shopify doesn’t allow this.

Is there a way to copy the top bar into the template so that I can design it independently of the rest of the website?

This is the code for the current top bar:

{% comment %}

** Top bar - static **

{% endcomment %}




{% assign id = section.id %}

{% comment %}Colors{% endcomment %}

{% assign background = section.settings.background %}

{% assign link = section.settings.link_color %}

{% assign link_hover = section.settings.link_hover_color %}

{% assign text = section.settings.text_color %}

{% comment %}Layout{% endcomment %}

{% assign width = section.settings.width %}

{% comment %} Advanced {% endcomment %}

{% assign css_class = section.settings.css_class %}

{% assign custom_css = section.settings.custom_css %}




{% comment %} Is the color set to transparent? {% endcomment %}

{% assign background_alpha = background | color_extract: 'alpha' %}

{% assign link_alpha = link | color_extract: 'alpha' %}

{% assign link_hover_alpha = link_hover | color_extract: 'alpha' %}

{% assign text_alpha = text | color_extract: 'alpha' %}




{%- assign locale_selector = false -%}

{%- assign currency_selector = false -%}




{%- if section.settings.show_currency_selector and shop.enabled_currencies.size > 1 or localization.available_countries.size > 1 -%}

  {%- assign currency_selector = true -%}

{%- endif -%}




{%- if section.settings.show_locale_selector and shop.published_locales.size > 1 -%}

  {%- assign locale_selector = true -%}

{%- endif -%}




{% comment %} Section specific CSS {% endcomment %}

{% capture section_css -%}

  .top-bar {

    font-family: {{ section.settings.font.family }}, {{ section.settings.font.fallback_families }};

    font-weight: {{ section.settings.font.weight }};

    font-style: {{ section.settings.font.style }};

    letter-spacing: {{ section.settings.letter_spacing }}px;

    font-size: {{ section.settings.font_size }}px;

    text-transform: {{ section.settings.font_style }};

  }




  a,

  .header__link .disclosure__toggle,

  .header__link .disclosure__button {

    color: {%- if link_alpha != 0 -%}{{ link }}{%- endif -%};

  }




  a:hover,

  .header__link .disclosure__toggle:hover,

  .header__link .disclosure__button:hover  {

    color: {%- if link_hover_alpha != 0 -%}{{ link_hover }}{%- endif -%};

  }




  p {

    color: {%- if text_alpha != 0 -%}{{ text }}{%- endif -%};

  }

{%- endcapture -%}




{% style %}




  {% if section.settings.enable_sticky %}

  .top-bar {

      position: -webkit-sticky; /* Safari */

      position: sticky;

      top: 0;

    }

  {% endif %}




  {{ section.settings.font | font_face }}




  #shopify-section-{{ id }} {

    background-color: {%- if background_alpha != 0 -%}{{ background }}{%- endif -%};

    {% if width == 'wide' %}

      width: 100%;

    {% endif %}

  }

  {% render 'css-loop',

          css: section_css,

          id: id

  %}

  {% render 'css-loop',

          css: custom_css,

          id: id

  %}

{% endstyle %}




{% comment %} HTML markup {% endcomment %}

{% if section.blocks.size > 0 %}

<section class="{{ css_class }}

                section

                is-width-{{ width }}">

  <div class="container">

    <header class="top-bar navbar is-justify-space-between one-whole column {% if locale_selector or currency_selector or settings.show_multiple_currencies %}disclosure-enabled{% endif %}{% if section.settings.enable_sticky %} is-sticky{% endif %}">

      {% for block in section.blocks %}

        {% if block.type == 'menu' %}

          {% comment %}Menu{% endcomment %}

          <div class="top-bar__{{ block.type | replace: '_', '-' }} is-justify-{{ block.settings.menu_alignment }}">

            <div class="top-bar__menu-items is-flex is-flex-wrap ">

              {% assign main_menu = linklists[block.settings.menu] %}

              {% for link in main_menu.links %}

                <a href="{{ link.url }}" class="navbar-link is-arrowless {% if link.active %}is-active{% endif %}">

                  {{ link.title }}

                </a>

              {% endfor %}

            </div>

          </div>

        {% elsif block.type == 'social_media' %}

          {% comment %}Social media{% endcomment %}

          <div class="top-bar__item top-bar__{{ block.type | replace: '_', '-' }}">

            <div class="navbar-item ">

              {% render 'social-icons' %}

            </div>

          </div>

        {% elsif block.type == 'text' %}

          {% comment %}Phone number{% endcomment %}

          <div class="top-bar__item top-bar__{{ block.type | replace: '_', '-' }}">

            {% if block.settings.icon != blank %}

              {%

                render 'icon',

                name: block.settings.icon,

                icon_class: 'header__top-bar-icon',

              %}

            {% endif %}

            <p class="navbar-item is-flex is-flex-wrap">

              {{ block.settings.text | replace: '[ch-flag]', '<svg width="16" height="16" viewbox="0 0 32 32" xmlns="
"><path d="M0 0h32v32H0z" fill="#da291c"></path><path d="M13 6h6v7h7v6h-7v7h-6v-7H6v-6h7z" fill="#fff"></path></svg>'}}

             </p>

           </div>

        {% endif %}

      {% endfor %}




      {% if locale_selector or currency_selector or settings.show_multiple_currencies %}

        <div class="top-bar__item top-bar__disclosure">

          {%

            render 'localization-switcher',

            additional_classes: 'header-menu__disclosure',

            id: 'header__selector-form--top-bar',

            currency_selector: currency_selector,

            locale_selector: locale_selector,

            show_currency: section.settings.show_currency_selector

          %}

        </div>

      {% endif %}




    </header>

  </div>

</section>

{% endif %}




<script>

  document.documentElement.style.setProperty('--top-bar-height', Math.round(document.getElementById('shopify-section-{{ id }}').clientHeight) + 'px');

</script>




{% schema %}

  {

    "name": "Top bar",

    "class": "top-bar",

    "max_blocks": 4,

    "settings": [

      {

        "type": "header",

        "content": "Colors"

      },

      {

        "type": "color",

        "id": "background",

        "label": "Background",

        "default": "#ffffff"

      },

      {

        "type": "color",

        "id": "link_color",

        "label": "Link",

        "default": "rgba(0,0,0,0)"

      },

      {

        "type": "color",

        "id": "link_hover_color",

        "label": "Link hover",

        "default": "rgba(0,0,0,0)"

      },

      {

        "type": "color",

        "id": "text_color",

        "label": "Text",

        "default": "rgba(0,0,0,0)"

      },

      {

        "type": "header",

        "content": "Typography"

      },

      {

        "type": "font_picker",

        "id": "font",

        "label": "Font",

        "default": "open_sans_n4"

      },

      {

        "type": "select",

        "id": "font_style",

        "label": "Capitalization",

        "default": "none",

        "options": [

          {

            "value": "none",

            "label": "None"

          },

          {

            "value": "lowercase",

            "label": "Lowercase"

          },

          {

            "value": "uppercase",

            "label": "Uppercase"

          }

        ]

      },

      {

        "type": "range",

        "id": "font_size",

        "label": "Base size",

        "min": 10,

        "max": 20,

        "default": 14,

        "unit": "px"

      },

      {

        "type": "range",

        "id": "letter_spacing",

        "label": "Letter spacing",

        "min": 0,

        "max": 6,

        "default": 0,

        "unit": "px"

      },

      {

        "type": "header",

        "content": "Sticky header"

      },

      {

        "type": "checkbox",

        "id": "enable_sticky",

        "label": "Enable sticky on scroll"

      },

      {

        "type": "header",

        "content": "Language selector",

        "info": "To add a language, go to your [language settings.](/admin/settings/languages)"

      },

      {

        "type": "checkbox",

        "id": "show_locale_selector",

        "label": "Enable language selector",

        "default": true

      },

      {

        "type": "header",

        "content": "Country selector",

        "info": "To add a country, go to your [payment settings.](/admin/settings/payments)"

      },

      {

        "type": "checkbox",

        "id": "show_currency_selector",

        "label": "Enable country selector",

        "default": true

      },

      {

        "type": "header",

        "content": "Layout"

      },

      {

        "type": "select",

        "id": "width",

        "label": "Width",

        "default": "standard",

        "options": [

          {

            "value": "standard",

            "label": "Standard"

          },

          {

            "value": "wide",

            "label": "Wide"

          }

        ]

      },

      {

        "type": "header",

        "content": "Advanced",

        "info": "[Learn more](https://help.outofthesandbox.com/hc/en-us/articles/360022329373)"

      },

      {

        "type": "text",

        "id": "css_class",

        "label": "CSS Class"

      },

      {

        "type": "textarea",

        "id": "custom_css",

        "label": "Custom CSS"

      }

    ],

    "blocks": [

      {

        "type": "menu",

        "name": "Menu",

        "limit": 1,

        "settings": [

          {

            "type": "link_list",

            "id": "menu",

            "label": "Menu",

            "info": "This menu won't show drop-down items."

          },

          {

            "type": "select",

            "id": "menu_alignment",

            "label": "Menu alignment",

            "default": "center",

            "options": [

              {

                "value": "start",

                "label": "Left"

              },

              {

                "value": "center",

                "label": "Center"

              },

              {

                "value": "end",

                "label": "Right"

              }

            ]

          }

        ]

      },

      {

        "type": "social_media",

        "name": "Social media",

        "limit": 1

      },

      {

        "type": "text",

        "name": "Text",

        "settings": [

          {

            "type": "text",

            "id": "icon",

            "label": "Icon"

          },

          {

            "type": "text",

            "id": "text",

            "label": "Text",

            "default": "123 Main Street, Pleasantville USA"

          }

        ]

      }

    ]

  }

{% endschema %}
1 Like

Yup, shopify yet does not have the ability in my little knowledge as well to copy paste sections. What you can do here is use sidekick to generate a code for the top bar with all settings and stylings, or use the top bar that is already there and make your necessary changes.

You can then include it directly as code for that template or add the code in a snippet or section file and include that file on that specific template.

2 Likes

Shopify actually allows copy/pasting sections in “Edit theme” interface (right-click the section/block title for a menu), however, some sections can be strict on where they may appear.

So, say in Dawn you can copy the “Announcement bar” section, but can’t paste it into Template area:

Because it has this in section schema:

So yes, if your theme does not allow you to copy/paste top bar section into template the best way would be to either repurpose some other section (again, depending on what your theme offers) or ask AI to create a section for you.


if my post is helpful, please like it ♡ and mark as a solution -- this will help others find it
2 Likes

Hi again,
my current bar was built by professionals, I dont know how to rebuild it, especially not with the AI (I miss the “custom sections”). Thats why I’d like to copy it and remove all but two things in it.

I have the same situation as you in the pictures with the text “section-type not allowed”.
Well thanks for the clarification, I’ll try to do something.

Check for similar code enabled_on / disabled_on in the schema of your top bar section.

Also keep in mind that top bar was one of the sections we’ve hidden previously, so if the selector matches, it will be hidden too inside template area.

So does that mean I can adjust the enabled_on / disabled_on to my liking?

Yes, thank you, thats why I want to copy it ans put the copy on top in the Template section. That way I could make it unique for this template.

At first I did exclude it from your code wich hides the Head and edited it but noticed that it changed all over the website… of course :grinning_face_with_smiling_eyes:

1 Like

Yep, in my first post here there is a link to documentation. You can remove them (be careful to keep the JSON valid!).

Yes, Header and Footer are site-wide. Template is per template.

Thank you, it worked.

With the following code i pasted in the code of the top bar:

{% assign main_menu = linklists[block.settings.menu] %}

{% unless template.suffix == ‘example’ and main_menu.title == ‘example’ %}
{% for link in main_menu.links %}

{{ link.title }}

{% endfor %}
{% endunless %}

Note for future readers you may also need to change the section to have a unique id in the sections {% schema %}, when copying , duplicating, or transplanting section code around.