2

Joomla 3.9.12

I've been using Sourcerer in order to place custom code throughout my site, it's working well so far. I've created a custom html module, within this I have added PHP, JS, HTML and CSS. The purpose of the module is to select data from the database and display this information in a 'Customers' datatable.

I have duplicated this module and placed it on various pages and positions throughout my site. The issue I am having now is that when I need to make a change, I have to update the code manually within each custom html module. Ideally I'd like to make the change in one place.

For example, in the Joomla back-end I'd like to create new module > select type 'Customers Table' > select a position and page > save. I can duplicate this module as required. If at some stage I want to add an additional column to the 'Customers' table, I should be able to edit the PHP in one place, and the changes reflect across all the modules.

Should I be looking at creating a module, plugin or component? I'm not sure how to approach this. Never attempted custom Joomla development before, although I have read a lot of tutorials I'm not fully understanding the difference in modules, plugins and components.

My PHP code is accessing the database using JDatabase if that helps.

  • Could you place up a sample of the code you are running now that you want to make a single copy of. At first read I would say you would be needing to make a Module out of your code. – Irata Oct 25 at 22:28
  • @jonboy How can we drive this page toward a resolution? Do you require greater specificity in the answer provided? If so, you can leave a comment under the volunteer's answer and/or edit your question to further detail what you are needing help with. Please endeavour to never have an abandoned question attached to your account. Please give some of your attention to this page when you have a moment. – mickmackusa Nov 25 at 5:12
2

For the purpose you are describing, your best bet is to create your own Joomla custom library. It's a type of Joomla extension alongside with plugins, modules and components, allowing you to put your custom common code. There is not much examples in Joomla documentation but Roberto Segura (phproberto) made an awesome example of a custom library available on github. Just type phproberto/lib_sample. Here is the link for Joomla documentation on custom libraries Joomla documentation on custom libraries and another link for custom library sample code custom library sample code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.