We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Need Help Displaying Content Pages on Shopify Liquid

Need Help Displaying Content Pages on Shopify Liquid

charliehenry
Shopify Partner
13 0 2

Hi Shopify Community,

I'm working on a custom drawer accordion for my Shopify store and I'm having trouble displaying the content from metafield pages correctly. Here are the details:

 

Context:

  • Drawer Structure: I have a drawer (metaobject)  is containing multiple metafields: acc_title, acc_icon, acc_page, and acc_rich. each of them contains a list of values
  • Objective: I want to display content from these metafields in an accordion format, where each accordion section displays either content from acc_page or acc_rich, along with the title and icon.

Screenshot 2024-06-19 at 09.29.56.png

Issue:

  • The acc_page metafield values are not displaying correctly. They show up as null in my debug output.
  • The acc_rich, acc_title, and acc_icon metafields are working fine and displaying as expected.

 

Can you help me out please? what I'm doing wrong?

 

 

{%- if drawer != blank -%}
  {% assign acc_titles = drawer.acc_title.value %}
  {% assign acc_icons = drawer.acc_icon.value %}
  {% assign acc_pages = drawer.acc_page.value %}
  {% assign acc_rich_texts = drawer.acc_rich.value %}
  
  {% assign array_size = acc_titles.size | minus: 1 %}
  
  {%- for i in (0..array_size) -%}
    {% assign title_value = acc_titles[i] %}
    {% assign icon_value = acc_icons[i] | downcase | replace: " ", "-" | replace: "_", "-" | replace: ".", "-" %}
    {% assign page_value = acc_pages[i] %}
    {% assign rich_value = acc_rich_texts[i] %}
    
    {%- if rich_value != blank or page_value.content != blank -%}
      {%- capture item_content -%}
      <div class="prose">
        {%- if page_value.content != blank -%}
          {{ page_value.content }}
        {%- else -%}
          {{ rich_value | metafield_tag }}
        {%- endif -%}
      </div>
      {%- endcapture -%}
      
      {%- render 'accordion-dynamic', icon: icon_value, title: title_value, content: item_content, class: 'product-info__accordion', block: block -%}
    {%- endif -%}
  {%- endfor -%}
{%- endif -%}

Thank you,

 

Replies 3 (3)

Kyle_Poieo-Dev
Shopify Partner
54 6 9

If debugging is returning null, that means that the acc_page isn't being populated properly. Before ruling out bugs, have you tried adding debugging code outside of your conditional?

-

Need a Shopify developer? Send me an Email


- CEO & Lead Developer at Poieo Dev
- Shopify Design Changes | Shopify Custom Coding | Custom Modifications | SEO | E-Commerce Management
Poieo Dev
charliehenry
Shopify Partner
13 0 2

I still getting null, even before the loop, but I have make sure there is content on the page, I'm not quite sure, why I'm not getting any result.

Screenshot 2024-06-19 at 16.44.45.pngScreenshot 2024-06-19 at 09.53.44.png

Kyle_Poieo-Dev
Shopify Partner
54 6 9

What do you get when you debug "page_value"? Trying to trace it down, like if "page_value" is also null.

-

Need a Shopify developer? Send me an Email


- CEO & Lead Developer at Poieo Dev
- Shopify Design Changes | Shopify Custom Coding | Custom Modifications | SEO | E-Commerce Management
Poieo Dev