Re: How can I display the block name as the block type

How can I display the block name as the block type

xaicks
Visitor
3 0 0

How can I dynamically display the block name as the block type for each social link in this section, instead of using icons or the standard social type?

 

block-social-type.jpg

Screenshot 2024-10-11 at 04.56.17.png

Replies 4 (4)

Dan-From-Ryviu
Shopify Partner
10727 2121 2240

Add 'Social Name' in 'name' instead of 'social_type'

- Solved it? Hit Like and Accept solution! ❤️Buy Me Coffee❤️
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

xaicks
Visitor
3 0 0

Yes, I can do that, but I want to show the related social name for that instance in the block

xaicks
Visitor
3 0 0

This is what I intend to achieve: using the social name in the block to avoid having the same label for all the social links.

 

Screenshot 2024-10-11 at 15.06.03.png

 


In the block section, I am getting the social_type in the Social Name field, but I’m unsure how to dynamically populate the name block with this social_type value.

Screenshot 2024-10-11 at 15.07.08.png

Any help would be appreciated!
tks!



AmeliaRich
Tourist
7 0 2

 

To dynamically display the block name as the block type for each social link, rather than using icons or standard social types (like Facebook, Twitter, etc.), follow these steps:

1. Access the Social Link Block Data

Each social link should be stored as a block or object, typically with attributes like name (the custom label for the social link) and type (the standard social media type, like 'Facebook' or 'Twitter').

2. Replace the Icon or Social Type with the Block Name

Instead of displaying the icon or the default social type, use the block’s name attribute to replace the type. In code, you can dynamically inject the block name into the HTML or template.

Example in Javascript:

If you're handling social links with JavaScript, here’s an example of how you might swap the social type for the block name:

 

javascript
Copy code
const socialLinks = [ { name: 'My Business Page', type: 'Facebook', url: 'https://facebook.com/mybusiness' }, { name: 'Follow Me on Twitter', type: 'Twitter', url: 'https://twitter.com/myprofile' } ]; socialLinks.forEach(link => { const socialBlock = document.createElement('div'); socialBlock.innerHTML = `<a href="${link.url}">${link.name}</a>`; document.getElementById('social-section').appendChild(socialBlock); });

 

 

In this example, the name (e.g., "My Business Page") replaces the icon or social media type in the rendered section.

3. Update the Frontend Layout

If you're using a templating engine (like Handlebars, Django templates, or others), replace the block where you usually show the icon with the dynamic block name.

Example in Handlebars:

 

html
Copy code
{{#each socialLinks}} <a href="{{url}}">{{name}}</a> {{/each}}

 

 

Here, {{name}} dynamically displays the block name for each social link.

4. Ensure Proper Styling

Since you're not using icons, ensure that your custom block names are styled appropriately. Use CSS to make the names visually appealing in your section.

Example:

 

css
Copy code
.social-link a { font-size: 16px; color: #333; text-decoration: none; }
 

5. Test Responsiveness

Ensure the section still looks good across different devices and screen sizes. Since you're displaying text instead of icons, adjust font sizes or layout as needed.

Conclusion

By accessing the block name and dynamically replacing the default social type or icon, you can create a personalized section for social links. This method allows you to display custom names or labels for each link, giving you more flexibility in how you present social connections.