Retrieve module id in Joomla xml element

/ Published in: PHP
Save to your folder(s)

It's not possible to use the standard syntax to retrieve the current id of the Joomla module in a Joomla xml element. This code parses the url and grabs the last part of the url which i atypically the module id when editing a module in the Joomla admin.

We used this to create a unique cookie for each instance of the module.

Copy this code and paste it in your HTML
  1. // Workaround to get the module id via the url.
  2. $moduleID = JUri::getInstance()->toString();
  4. // Split the url instance so we can get the moduel id
  5. $moduleID = split("=",$moduleID);
  7. // The fourth = last variable in the module admin so we set the cookie name to that
  8. $cookieName = "listOrder".$moduleID[4];

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.