Hi all, I had a situation where I needed to add small contact form on every page, or most pages in the body of the page for a large website. The situation I have is that it could change from time to time, if it does then I have to change it manually on every page.
I know there has been discussion and asking about global content in page body, so I thought I’d share the solution I’ve come up with to deal with this, it may be useful for folk until global content is implemented in Blocs in the future.
Basically, you create a bloc of content in the footer and hide it. You then add a div container wherever you want in your body and it will display the hidden content from the footer there.
These are the steps:
-
Add bloc in footer, set padding to none across all breakpoints, start Small it will cascade up to all breakpoints.
-
Add Div Container in the bloc. Add content in this Div.
-
Add a class to this Div, in this case it is global-content-1, in this class set Visibility to hidden when finished.
-
Add a Bloc and Div in the body of your page. Give this Div a unique ID that will not be used elsewhere. In this case it is content-display-1
-
Add a bloc in the footer. Again add padding across all breakpoints as none.
-
Add a code widget in this bloc.
-
Copy and paste the javascript in to this code widget.
Javascript:
<script>
document.addEventListener("DOMContentLoaded", function() {
const globalBloc = document.querySelector('.global-content-1');
const placeholder = document.querySelector('#content-display-1');
if (globalBloc && placeholder) {
placeholder.innerHTML = globalBloc.innerHTML;
}
});
</script>
Remember if you go mad with global content, it is loading on every page in the footer and just hidden so will increase your page size.
I might try looking at whether I can get the global content to go on it’s own non-indexed page and be brought in so it isn’t heavy on the footer, but for the moment this works for me.
Sample file with this I’ve just knocked up to demonstrate below.
Enjoy
Ben
Global Content Test.bloc (119.3 KB)