Download the PHP package mvrk/icenberg without Composer
On this page you can find all versions of the php package mvrk/icenberg. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mvrk/icenberg
More information about mvrk/icenberg
Files in mvrk/icenberg
Package icenberg
Short Description Library to abstract away Advanced Custom Fields flexible content markup
License MIT
Informations about the package icenberg
Icenberg 🥶
- Icenberg 🥶
- What is it?
- Getting Started
- Icenberg Methods
enclose()
settings($field_name, $additional_classes)
- Conditionals
field($field_name)
is($value)
lessThan($value)
andgreaterThan($value)
- Maverick Specific
get_buttons($field_name)
andthe_buttons($field_name)
- Supported fields
- Currently Supported fields
- Third party fields:
- Special Fields
What is it?
This requires ACF Pro and is primarily for internal use at Maverick, although it is easy to implement on any WordPress template using ACF's Flexible content fields.
Icenberg is an attempt to clean up ACF Flexible content block templates which often involve a lot of repetition and logic tangled up in presentation, in true WordPress style.
Using Icenberg's methods we can render any acf fields complete with BEM classes and settings in a clean(er) OO fashion, while still allowing us to do things the old fashioned way if necessary.
It is designed to be used primarily with flexible content fields as it asumes the existance of 'the row' but could also work within non-flexible groups and repeaters, in theory.
Note: The buttons
and settings
methods rely on Maverick specific setups, we'll make these more generally usable in the future.
Getting Started
Install via composer:
make sure autoloading is set up in functions.php - something like:
Make sure you have ACF Pro installed. The library also supports ACF Gravity forms plugin.
The following all takes place inside ACF's the_row() - ie:
Initialise with ACFs the_row_layout()
Once that's intialised you're ready to build your block.
Icenberg Methods
get_element($field_name, $tag = 'div')
Returns an ACF field as a formatted string, wrapped up in all the divs you need and with any special considerations applied. Takes the field name as an argument and optionally a tag for the uppermost element. If no tag is set it will use 'div'
the_element($field_name, $tag = 'div')
As above, but echoes it out immediately.
Icenberg is smart enough to know what a field's type is, so you don't need to differentiate, you just pass the field name in.
enclose()
Enclose is a utility for wrapping multiple icenberg fields in a container div without having to use a ?> anywhere. You just need to pass it a classname (without prefixes as these will be applied by icenberg). So clean!
So for example, in a 'Cta' block, where cta_heading is a text field and cta_content is a wysiwyg field:
will generate:
You could also pass any thing else you like to enclose as part of the array, as long as its storable as a variable (for example inserting a get_template_part()
won't work here because it effectively prints the content).
Of course life is never simple, so you will most likely need more complex layouts, but icenberg doesn't mind. You can insert it in html if you want to.
settings($field_name, $additional_classes)
Pass in a field group of settings and optionally an array of manually set classes and it will attach them as CSS modifier classes. if you include a text field called 'unique_id' in your group icenberg will attach it as a id too.
Example using settings in enclose()
:
or in regular php/html
which will print out something like
Depending on the settings in your group.
Conditionals
field($field_name)
you can use icenberg to evaluate fields too, using the field()
method in conjucntion with the below methods. field()
takes the field name as an argument and returns the icenberg instance for method chaining.
is($value)
returns true if the value of the field equals the argument to is()
. You don't need to check for a fields existance before using these methods as they will do it for you and return false
if they don't.
lessThan($value)
and greaterThan($value)
Self explanatory, both take an integer as an argument. Warning: If you use it on a non numeric field it will return false.
Maverick Specific
get_buttons($field_name)
and the_buttons($field_name)
Return a formatted button group with a huge range of styles catered for - very Maverick specific. Expects our usual button group format.
Supported fields
Currently Supported fields
- Gallery
- Group
- Image
- Link
- Number
- OEmbed
- Range
- Repeater
- Select
- Text
- Textarea
- Wysiwyg
Third party fields:
- Forms
- Swatch
Special Fields
- Buttons
- Settings