Support Forum
Hi there,
I need some help understanding how the background field
works.
I have it implemented, and it shows up the way it's supposed to and holds all the values it's supposed to....great!
However I am having a hard time outputting the information from the background field
. I have read the documentation here: https://docs.metabox.io/fields/background/ but I just can't seem to wrap my head around it.
Could you possibly provide an example of what to do, maybe just a small tutorial on how to use the background field
and apply the information from the field to a simple div
?
I think this would be a great addition to the tutorial section.
Any help is greatly appreciated. Thanks in advance.
Hi Thomas,
The background field saves details into an array. If you use the helper function rwmb_meta()
to get its value - you'll get an array.
To get the generated CSS for the background, please use the function rwmb_the_value()
.
This is the sample code:
$bg = rwmb_meta( 'field_id' );
echo $bg['color']; // Output a single background attribute
// Get CSS for background
$css = rwmb_the_value( 'field_id', '', '', false );
echo $css;
Hi Anh,
Wow, I thought you would try and explain a little bit more than repeating what is already in the docs located here https://docs.metabox.io/fields/background/
I'm sorry I forgot to mention that I did try both of those methods.
So again I ask, maybe you can do a little tutorial and show me and others how to add a background image to a container. Nothing fancy, something super duper easy.
Trust me, it's very confusing.
Yes No?
Or maybe this: A tutorial on how to actually use rwmb_meta()
and rwmb_the_value()
.
Like how would I actually use:
$css = rwmb_the_value( $field_id, '', '', false );
echo '';
(taken from the background field documentation...doesn't seem to work properly though) and use it to show a background image for div.
I tried using the code I pasted from the background field
docs and it doesn't even work. In the example given the css is supposedly wrapped in a div
but it doesn't work.
Hi Thomas,
I'll create a tutorial and video to demonstrate how those helper functions work and what is the difference between them. Please wait a little.
Thanks,
Anh
Oh yeah most def. Sorry if I seem overly excited but I have reached a certain point in this project and I'd like to get it done and move on to the next part...again sorry.
I think you should do this for all the fields: Make a tutorial or a video or both. I know this would make your site even more AWESOME.
Thanks again for the help. I appreciate it.
Hi Thomas, here is the video tutorial:
Please pay attention to the text I wrote in the video :).
Hope you like it.
Anh
Hi Anh,
How would I attach the background to an existing div in a template in Oxygen builder?
Thanks,
Quint