Amadaeus Posted October 6, 2021 Posted October 6, 2021 Hi everyone. I could use some help from the hive mind on how to do what I'm trying to do... efficiently. Webpage is going to be about 30-40 pages Using Will-Myers Nav Replacement Javascript plugin so that 50% of the pages will have Navbar "A" while the other 50% will have Navbar "B" Navbars "A" and "B" are being code injected into each page right now As you can imagine, that last bullet point isn't very sustainable in the long term. If we want to change the navbar, I really don't want to have to go into the code for 20+ sites to change it. It's a recipe for a human-made mistake disaster. Is there a way for me to inject a reference to a centrally-controlled <div> block so I can make a change in one place and cascade to the affected pages? Thanks for your help everyone!
Beyondspace Posted October 6, 2021 Posted October 6, 2021 1 hour ago, Amadaeus said: Hi everyone. I could use some help from the hive mind on how to do what I'm trying to do... efficiently. Webpage is going to be about 30-40 pages Using Will-Myers Nav Replacement Javascript plugin so that 50% of the pages will have Navbar "A" while the other 50% will have Navbar "B" Navbars "A" and "B" are being code injected into each page right now As you can imagine, that last bullet point isn't very sustainable in the long term. If we want to change the navbar, I really don't want to have to go into the code for 20+ sites to change it. It's a recipe for a human-made mistake disaster. Is there a way for me to inject a reference to a centrally-controlled <div> block so I can make a change in one place and cascade to the affected pages? Thanks for your help everyone! Each page/section has it own unique id, we can use this technique to identify page element placement, could you share your site url? 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
creedon Posted October 6, 2021 Posted October 6, 2021 It's hard to envision exactly what you have going without being able to see sites/pages in action. What you might be able to do is take the div and put that into a file on your computer. Then upload that one file to one site using the link page file upload trick. Then with Javascript, read that file in and place that onto your sites where needed. Then from there all you need to do is update your div file on your computer and re-upload it when you need to make changes. Not sure if that flow would work but the main take away is to get that div into a place where it can be read and placed by Javascript. 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.
Amadaeus Posted October 6, 2021 Author Posted October 6, 2021 Thanks for the info so far. @creedon: Is there a guide to use javascript to read the file and place the code on the site?
Amadaeus Posted October 6, 2021 Author Posted October 6, 2021 Okay. I'm trying to use javascript import and it doens't seem to want to work. In the code header: <span id="new-site-title"> <script> import {str} from '/s/navbar.js'; document.getElementById("new-site-title").innerHTML = str; </script> In a .js file let str = ` <div data-wm-plugin="new-nav" style="height:0px;opacity:0;visibility:hidden"> <div class="new-site-title" id="new-site-title" href="/new-home">New Site Title</div> <div href="/new-home">LINK A</div> <div href="/new-home">LINK B</div> <div href="/new-home">LINK C</div> </div>`; export { str }; What I'm trying to do is to insert the entire string in $str into the header, or anywhere in the page really because the code will run from anywhere on the page
creedon Posted October 6, 2021 Posted October 6, 2021 This is not a solution but more of an example of what I was thinking of. You'd have a file nav.html uploaded somewhere. Then with jQuery do something like the following. var url = '/s/nav.html' $.get ( url, function ( data ) { const $nav = $( data ); console.log ( $nav ); } ); 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.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.