-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using enqueue to run a localized script #143
Comments
Seems that no matter what I do to make the DB call for the get_field, it will always return either null or default to my final ternary expression. |
codepuncher
added a commit
to codepuncher/acf-composer
that referenced
this issue
Dec 21, 2022
Ref Log1x#144 and Log1x#143 I have played about locally on this and seems we can simply pass the `$block` array to the `enqueue` method which gives access to `$block['data']['my_field_name']`. This allowed me to conditionally enqueue assets depending on field values. This PR needs more work like adding the argument to `Block::enqueue($data = [])` but I opened the PR just to get the ball rolling on this. It would result in a breaking change since the signature has changed. @Log1x - anything to add to this? Not as nice as `get_field` in the method but hey it works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I am looking to build a block that will support something like React or Vue. I see you have the
enqueue
method here, which executes the Sage 10 bundle code, however, I noticed that any data I need from this block is not passable. I am wondering if there is something I need to do differently, or another way to approach this.Basically in Sage 9, what I do in the Controller file is just run
wp_enqueue_scripts
passing in the get_field functions to the array data. Since I'm using gutenberg blocks, I'm not 100% familiar with executing this, or if this package allows the support of this.This is what my enqueue block looks like, and the post_id is being set as such due to it being a page declared to "page_for_posts". I can get the values on the front end but just not these localize values.
This is what the frontend returns:
The text was updated successfully, but these errors were encountered: