DSA Web Specialists
DSA Web Specialists

Reputation: 311

How do I add external links in Shopify Schema?

I've tried using "type": "url:". and apparently that only works for collections. I want to make a dynamic external link. I tried text input. Why is this one task not easy to do?

 <a class="section-tiktok__card" href="{{block.settings.url}}">
            <img src="{{ 'tik-play-btn.svg' | asset_url }}" alt="play video">
        </a> 


{% schema %}
    {
    "name": "TikTok Feed",
    "presets": [{
        "name": "TikTok Section"
    }],

    "blocks": [{
        "type": "html",
        "limit": 5,
        "name": "TikTok and Instagram Feed",
        "settings": [
            {
                "type": "image_picker",
                "id": "tiktok_bg",
                "label": "Image Background"
            },
            {
                "type": "url",
                "id": "tiktok_url",
                "label": "Tiktok or Instagram URL"
            }
        ]
    }]
}


{% endschema %}```

Upvotes: 0

Views: 1165

Answers (1)

Nathan Dawson
Nathan Dawson

Reputation: 19318

You're attempting to get a setting from a block but you haven't accessed your section blocks or assigned anything to block. Furthermore, your setting is named tiktok_url while you're using url to display it.

{% for block in section.blocks %}
    <a class="section-tiktok__card" href="{{ block.settings.tiktok_url }}" {{ block.shopify_attributes }}>
        <img src="{{ 'tik-play-btn.svg' | asset_url }}" alt="play video">
    </a> 
{% endfor %}

Upvotes: 1

Related Questions