Jump to content

Load pre-formatted text in a code block

Go to solution Solved by creedon,

Recommended Posts

Posted

For the 'additional info' below a product, I would like to use a code block that loads pre-formatted text from a file on my web server (either uploaded through the Squarespace interface or via FTP, whichever works best). I want to do this so that I can change the additional information for all products on the website at once, by changing only one document, instead of manually going through all products one by one. It would save a lot of time,and minimize the chance of errors.

The website is built on 7.0 in the Brine family.

How can such a thing be achieved? Thanks for your input.

Posted
7 hours ago, Burchard said:

For the 'additional info' below a product, I would like to use a code block that loads pre-formatted text from a file on my web server (either uploaded through the Squarespace interface or via FTP, whichever works best). I want to do this so that I can change the additional information for all products on the website at once, by changing only one document, instead of manually going through all products one by one. It would save a lot of time,and minimize the chance of errors.

The website is built on 7.0 in the Brine family.

How can such a thing be achieved? Thanks for your input.

I suggest you place the content into a external page and load the page content into your product page using AJAX request

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Pinch/Zoom images, videos - PDFs Lightbox - ...) </>  🗓️ Delivery Date Picker (Date picker form field)
Gallery block 7.1 workaround </> 🤖 Ask me anything

Posted
1 hour ago, Beyondspace said:

I suggest you place the content into a external page and load the page content into your product page using AJAX request

Thanks for your reply!

Can you explain how to do this? I'm not familiar with using AJAX requests.

  • 5 weeks later...
Posted

Giving this a bump.

I would really like to achieve this, but do not have any experience using AJAX requests. It would be great if someone can give me directions. Thanks!

Posted (edited)
Quote

loads pre-formatted text

Can you tell us more about this formatted text? Is it text that can be input into a text block and maintain the formatting you want?

AJAX is one way to go. Another way that is commonly used is to put a block in the site footer, hide, then use code to move it into place. Which method you use may be driven by the complexity of the formatted text you mention.

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Posted
11 hours ago, creedon said:

Can you tell us more about this formatted text? Is it text that can be input into a text block and maintain the formatting you want?

AJAX is one way to go. Another way that is commonly used is to put a block in the site footer, hide, then use code to move it into place. Which method you use may be driven by the complexity of the formatted text you mention.

It will be two text blocks, divided with a line block, with some bold text and one or two hyperlinks. I think the solution with the hidden block in the footer might be a good way to achieve this.

How would you go about this?

Posted
15 hours ago, Burchard said:

How would you go about this?

A basic overview.

Create a text block in the footer with your text.

Hide that text block with CSS.

Note the block id of the text block.

Create a code block in the product Additional Info that contains the following.

<x-placeholder></x-placeholder>

Use the following code to replace the code block in additional info.

The settings in the code would look something like the following. This is an example.

      '#block-64797599d9caa1491329a76c' : {
      
        selectorDestination : 'x-placeholder',
        
        // selectorParentDestination is optional
        
        selectorParentDestination : '.sqs-block-code',
        
        action : 'replace' // values are append, prepend or replace
        
        },
        

This is not a solution as we would need to see some of these elements in action on a site to provide a solution.

Another note. If you end up needing to moving a group of objects together as a design, this idea may not be appropriate.

 

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Posted
13 hours ago, creedon said:
 '#block-64797599d9caa1491329a76c' : {
      
        selectorDestination : 'x-placeholder',
        
        // selectorParentDestination is optional
        
        selectorParentDestination : '.sqs-block-code',
        
        action : 'replace' // values are append, prepend or replace
        
        },
        

Thank you for your solution.

I've made the adjustments, but I'm not sure where I should add this bit of code?

  • Solution
Posted
Quote

Maybe you can spot where I am failing?

In part the failure is mine. I had a syntax error in my code.

Replace the following in the code...

      /* '[enter selector source here between single quotes replacing square brackets]' : {
      
        selectorDestination : '[enter selector destination here between single quotes replacing square brackets]',
        
        /*
        
          selectorParentDestination is optional, use when you want to first find
          a selector destination but then work up the ancestor hierarchy to
          manipulate it
          
          */
        
        selectorParentDestination : '.sqs-block-code',
        
        action : 'replace' // values are append or replace
        
        }, */
        
      '#block-yui_3_17_2_1_1686202370694_2971' : {
      
        selectorDestination : 'x-placeholder',
        
        /*
        
          selectorParentDestination is optional, use when you want to first find
          a selector destination but then work up the ancestor hierarchy to
          manipulate it
          
          */
          
        selectorParentDestination : '.sqs-block-code',
        
        action : 'replace' // values are append, prepend or replace
        
        },
        

...with the following code.

      /* '[enter selector source here between single quotes replacing square brackets]' : {
      
        selectorDestination : '[enter selector destination here between single quotes replacing square brackets]',
        
        // selectorParentDestination is optional, use when you want to first
        // find a selector destination but then work up the ancestor hierarchy
        // to manipulate it
        
        selectorParentDestination : '[enter selector parent destination here between single quotes replacing square brackets]',
        
        action : 'append' // values are append or replace
        
        }, */
        
      '#block-yui_3_17_2_1_1686202370694_2971' : {
      
        selectorDestination : 'x-placeholder',
        
        // selectorParentDestination is optional, use when you want to first
        // find a selector destination but then work up the ancestor hierarchy
        // to manipulate it
        
        selectorParentDestination : '.sqs-block-code',
        
        action : 'replace' // values are append, prepend or replace
        
        },
        

Replace your footer hiding CSS with the following.

html:not( .squarespace-damask ) .Footer #block-yui_3_17_2_1_1686202370694_2971 {

  display : none;
  
  }

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Posted (edited)

That worked like a charm, thanks a lot! I imagine this will be helpful for others as well, thank you for your generosity in sharing your skills and the code, much appreciated!

Edited by Burchard
grammar

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.