wp-papi / papi

:rocket: WordPress Page Type API with custom fields
https://wp-papi.github.io
MIT License
263 stars 32 forks source link

Arguments to before_html and after_html #214

Closed sasimon closed 7 years ago

sasimon commented 7 years ago

Hello! I came here from CMB2 expecting that the _beforehtml and _afterhtml property options would work just like CMB2's _beforerow and _afterrow. CMB2 does not support empty repeating groups or nested repeating groups, both of which I also need. Be that as it may, when CMB2 receives a user-defined function as the value of _beforerow and _afterrow, it passes two arguments to the function: (1) the field's value at load time and (2) the field object itself. What I am suggesting is that by adding these two arguments to the _beforehtml and _afterhtml user function calls (or at least passing the field object), Papi can accommodate something much larger. Namely, Papi can now accommodate the need to render different display HTML in different "records" of repeater groups. Thank you!

frozzare commented 7 years ago

I haven't used CMB2 and haven't looked at how it works.

before_html and after_html takes a string of html that are rendered before and after the property html. Maybe that the case of what before_row and after_row does, but I don't know.

There will be now change of how before_html and after_html works since they works as the should now. If you like to print out data from the database with before_html and after_html you can just do before_html => papi_get_field( 'name_slug', 'Default value' ) or something like that.

If you like different layouts for each repeater row you should have a look at flexible http://wp-papi.github.io/docs/properties/flexible.html