How to call attributes

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.

Does anyone know how to call an attribute?

Attributes are variables - there is no language where they are “called”.

What is it that you wish to do with the attribute?

I have a feeling that somewhere you are going to need javascript. Javascript is the equivalent of Swift for web pages.

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’ve coded a little bit with JavaScript.

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.

Hi @KG7UAT

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 :wink:

Bill
BricsDesign

2 Likes

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.

Thanks for the answers so far!

@Bill Your explanation is very deep, and a bit over my head. I’ll have to chew on it for a while. Thanks anyways! It looks to be very helpful.

@Norm I like your idea of looking at a Bric example. Why hadn’t I thought of that? Thanks for your help!

1 Like