We've created a new package that is intended to facilitate the replacement of custom PHP modules with custom Display Template modules. It also demonstrates how to create custom API functions in general. You will find this package attached below.
Steps to replace a PHP module Module
Edit the api/main.php file- Find the customWidgetHtml function
- Copy your PHP code from the module into the function.
- Change the code to generate a string value instead of echoing content and set that to the $myhtml parameter.
If you have more than one PHP module you can copy the function, give it a new name, and copy/edit the code above for each module.
- Upload this package directory into core/packages
Create a custom template- Go to the style editor in the admincp and select add a new template for the site style you are using.
- Give it a name like 'customtemplatemodule'
- Copy the following into the template changing the name to match the function name(s) in the api/main.php:
{vb:data result, localapi:main, customWidgetHtml}
{vb:raw result.html}
- Do this for each PHP module you are replacing.
Adding Your Code to a Page- Go to sitebuilder.
- Edit the page that you want to display the module on.
- Add a "Display Template" Module to replace the PHP Module
- Set the template name to 'customtemplatemodule' or whatever you named your new template.
- Remove the old PHP module template
- Save the Page.
Note you can return HTML and display it from the API in this way. It's the quickest and easiest way of porting from an existing PHP module to a Template module. But it isn't necessarily the best way. The API functions are intended to return data that can be inserted into the markup in the templates. An alternative example is provided in the sample class. You can uncomment the function if you want to try it out. The template to use this to provide the same result as the sample HTML return is:
{vb:data result, localapi:main, dataOnly}
<p>{vb:var result.hello}</p><p><b>{vb:var result.hellobold}</b></p>
As above save that as a custom template and create a Display Template Module that uses it.