Home › Forums › Gutenberg › Difference between render_template and render_callback? › Reply To: Difference between render_template and render_callback?
I have not played with this much, but I think it’s really a matter of coding style.
As in @koolkatwebdesigns case she is using a combination of styles.
Templates, like template parts, let you have imaginably chunks of code. Some like template parts because they can look at a theme folder and immediately know what file is doing what to know where to make changes (as long as the template parts are named well that is). Callback functions can be harder to track down.
Going back to the other commenters example I could also create one render_template and then do multiple things in that single template based on the ACF fields. Or I can do the same thing in a single callback function. The solution of making a choice and loading different templates instead keeps code more manageable and allows for easier extension. This could also be accomplished by creating additional functions that can be called from the main callback function.
I generally let my goal dictate what style I’d use in each case. But I do like using templates for the reason I mentioned. I name them well and I can look at the template files and know which one to edit. I try to do this with functions and filters I create, but generally I end up with large files that are doing multiple things and it becomes more difficult to find the callback function I need to edit. Given this I would likely go with a template as my first choice.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!