Support

Account

Home Forums Front-end Issues HTML template output for custom field type

Solved

HTML template output for custom field type

    • geraldo

    • February 10, 2020 at 9:11 pm

    I followed the guide for Creating a new field type and have a question about a topic which is not covered there:

    I want to include the personalized HTML output of the field type in the template on the front end. Right now I define the visual part of the output in a template file, now I try to include that code in the plugin so I can render it in the template by calling get_field().

    Is there a method similar to render_field() for rendering the field on the front end?

    Note: I created a Openlayers backend map to store latitude and longitude values. Now I want to output a map with the marker position in the template.

  • You would use the format_value method for something like this.

    • geraldo

    • February 21, 2020 at 11:19 pm

    Great, thanks! Using format_value() works out great to return a div as $value for rendering the map.

    Where would I put the javascript in this case, is there something like input_admin_enqueue_scripts() but for front end?

  • There is also a commented out function (method) in the ACF example that will be called when scripts are enqueued where you can enqueue any custom scripts that you need.

    • geraldo

    • February 22, 2020 at 2:14 am

    Should be in the class-NAMESPACE-acf-field-FIELD-NAME-v5.php file right? I can’t find that, the functions which look promising are only being called on the edit screen…

  • oh, you want the script to be enqueued on the front end. That needs to be done when the field is output on the front end. You can either include inline code in the formatting or you could enqueue the script when it is formatted.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.