I hope I’m not asking a stupid question, but the answer is not obvious to me.
So, I’m attempting to make a custom bric in Blocs (my first one) and I need to call data from an attribute called my-data which contains data from a text field set by the user in the interface. I don’t have a lot of experience in HTML, most of my experience is in Visual Basic and Swift, but I’m assuming an attribute in HTML is similar to a variable in other languages. But I cannot figure out how to call that attribute in HTML. I tried looking it up on Google, but I’m just more confused.
I want to use the data in the attribute. So, in the interface, I have a text field where people can put the link or path to the audio. I will then use the data in the attribute in my code where the code requires a link, I will use the data in the attribute. I’ve heard some programmers referring to this as “calling” the data of a variable (or attribute). Hope that makes sense (I have difficulty trying to communicate what I want to say sometimes).
I haven’t used the bric builder, but I think the function name needs to be the name of a javascript function that will be called with the my-data attribute as a parameter.
The name of the javascript function depends on the media player, I guess.
There’s no stupid questions, but FYI - building a bric is VERY INVOLVED !
Set a function name that describes the control, this will be used later.
Set an attribute for the value that will be entered. This is for Blocs to internally keep track of everything, it’s never used again.
Set a default value, or leave it blank.
Every value, whether for css or js, etc. has to be stored in the html as data attributes, ie. data-something=“my data”.
For changes in edit-mode, you call the function inside the custom-bric.js in the js folder & then do whatever you want w/ it and then send it back to be written to the html using a sync command.
For stuff that happens on page load, you call the data-something values that’s are in the html from a publish.js file in the includes folder & then write js to do some kind of action.
If you haven’t already, you need to read the API docs about a 100 times till it starts to make sense, but the above steps are a general outline of what you need to do.
I’m sure this all just went way over your head, but you did ask
I’d recommend looking at one of the bric examples you should see how to connect a UI item to a function there.
With a text field, the attribute name you give the text field is automatically handled for you, so when data is entered it’s stored as an attribute in whatever name you assign (myattribute). To use the attribute you just need to write a function and feed the attribute variable into it ie myfunction(myattribute)
This function is also called when the input text is changed, with your function you decide what chages and how this data is used in the Brics DOM.