Facebook Twitter Pinterest Share

vBulletin 5 Connect Articles Articles specializing in vBulletin 5.X Connect.


New Thread  Post Reply
JohnnyBoy's Avatar
JohnnyBoy : Rick Mills FTW?
JohnnyBoy is on a distinguished road
offline Joined: May 2016 Location: GYSN Posts: 321 Thanked: 181
  #1  
Thread Starter Unread 09-23-20
Including Custom PHP in Modules

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
  1. Find the customWidgetHtml function
  2. Copy your PHP code from the module into the function.
  3. 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.
  1. Upload this package directory into core/packages
Create a custom template
  1. Go to the style editor in the admincp and select add a new template for the site style you are using.
  2. Give it a name like 'customtemplatemodule'
  3. 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}
  4. Do this for each PHP module you are replacing.
Adding Your Code to a Page
  1. Go to sitebuilder.
  2. Edit the page that you want to display the module on.
  3. Add a "Display Template" Module to replace the PHP Module
  4. Set the template name to 'customtemplatemodule' or whatever you named your new template.
  5. Remove the old PHP module template
  6. 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.
Attached Files Click the thanks button to view this attachment.
Quote
Excellent vBulletin support @ GYSN Underground.
New Thread  Post Reply

Thread Tools

Bookmarks
  • Submit Thread to Facebook
  • Submit Thread to Twitter
  • Submit Thread to Pinterest
  • Submit Thread to LinkedIn
  • Submit Thread to Reddit
Tags
code, custom, display, function, including, module, modules, package, php, return, template
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Powered by GYSN Underground 2020