Editable Data-Attributes on Elements (Non-HTML)

Hey SiteJetters!

It seems a lot of SaaS are moving their web integrations to allow for data-attributes as key elements to integration.

The potential for editable “data-attributes” on elements could really open up the potential for integrations without knowledge of API work for some of those integrations, as well as prepare for scaling.

The largest con could be code injection that could break websites, requiring high amounts of support from SiteJet if users break their websites accidentally, from what I am aware.

I do know Webflow does offer this ability - is there any research that can be done for how to implement this without overhauling the entire SJ security layers?

One potential solution could be to allow us to create an HTML element as a wrapper container and add the data-attribute there. But when we use HTML, we can’t use the GUI to drag and drop native SJ elements and continue the build inside an HTML element. Is there a way to allow us to visually nest SJ content inside a <div data-attribute-name="value" ... ></div> ?

Perhaps a “data-attribute” container is simply a div that allows us to add data-attributes?

Thoughts? Perhaps this is already being addressed as well.

Cheers!

3 Likes

Hi @zachary,

you can use HTML elements and set it up where it is needed, and you can also set up an empty HTML element with data attributes in seconds, e.g:
<div data-app-id="abc123"></div>

2 Likes

To understand correctly, then anything inside that HTML element would have to be in written HTML as well - we couldn’t use the WYSIWYG editor and SiteJet elements?

2 Likes

Hi @zachary

thanks for your feature request! Could you elaborate on more specific use cases that you are trying to solve with custom data-attributes on containers? As far as I can oversee, most use cases are about filling empty <div>s with third-party content (like booking widgets, chatbots or similar). In such cases, a regular HTML element would do the job, since you don’t need to add further content into it. Maybe you have a specific provider in mind?

But I also have two hacky workarounds in mind that could help you in the meantime, but both need to be used with caution (!):

  1. You can use custom JS to add data attributes to elements that you identify through a CSS class, e.g.
    document.querySelector('.your-custom-class').dataset.appId = 'abc123';
    and execute third-party scripts after that. Here you can read more about accessing and manipulating data attributes with JS
  2. Using your browser’s developer tools you could manually add data-attributes to the
    <div class="inner">
    of any container so it reads
    <div class="inner" data-app-id="abc123">.
    After doing so, you can trigger a random change in the CMS to be able to save and save. But be careful about it, as this can destroy website contents if not done properly! Try within a test website first.
2 Likes

Thanks @malte !

The source for this was integrating Memberstack - you can have blocks of content become inaccessible based on data-attributes for non-logged in members.

I wanted to wrap multiple SJ container sections into one HTML Div that I could add that data-attribute on, but couldn’t seem to figure out how to do it natively.

Thanks for the workarounds! Number 1 is my next option.

Edit: regarding your understanding, you are correct - the main source was just being able to do it WYSIWYG style, rather than with DOM Manipulation.

2 Likes

+1 for this.

This it would be really nice to have. The possibility to define custom data-attributes using the UI.
It would also be great to bind these attributed to collection fields (making use of the dynamic data).

Here is an (implementation) example:
CleanShot 2021-06-14 at 18.24.11

2 Likes