1

I'm trying to use a filter function from a plugin, but it turns out two plugins that I have installed have the same function name and the wrong one is getting called. For now I edited the vendor files to rename the function, but I don't want that to be my final solution in case I want to upgrade the plugin later.

What is the best way to go about circumventing this type of conflict between two plugins?

  • "same function name" - they have the same Twig filter function name? – Brad Bell Oct 21 '19 at 19:14
  • @BradBell Yes they have the same Twig filter function name – Balls McHenry Oct 22 '19 at 6:38
1

You could get around this by creating your own renamed copies of those functions.

  1. Create a module.
  2. Copy the content of each affected plugin's twigextensions folder to your module's twigextensions folder.
  3. Adjust the namespaces in these files to match your module
  4. Rename the functions / filters in these files to something unique.
  5. Load these twigextensions in your module's main file (use statement plus Craft::$app->view->registerTwigExtension).
  6. You can now use the filters in twig by referencing the unique name you gave them.

If you haven't worked with modules before, you can use pluginfactory.io to scaffold a module that includes lots of example code, including all the required code to set up a twig extension.

To improve on this further, instead of a straight up copying of the twig extensions, refactor them to call the public functions in the original plugin files. This will ensure it's much less likely to break things when the plugin gets updated later.

| improve this answer | |
0

If two plugins have a Twig filter/function that has an identical name, then whichever one "wins" will be the plugin that is loaded first (alphabetically, I believe).

No real way I can think of to get around it other than to contact the plugin developers and have one of them change the name.

| improve this answer | |

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.