Widget:CategoryPages: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:
         const wrapper = document.getElementById('categoryPages');
         const wrapper = document.getElementById('categoryPages');
         const pages = data.query.categorymembers;
         const pages = data.query.categorymembers;
        if (pages.length == 0) {
          wrapper.appendChild(document.createTextNode("No pages found in this category"));
        }
         for (const pageIdx in pages) {
         for (const pageIdx in pages) {
           const page = pages[pageIdx];
           const page = pages[pageIdx];
Line 20: Line 23:
         }
         }
       }).catch(function(err) {
       }).catch(function(err) {
         console.log('Fetch Error :-S', err);
         wrapper.appendChild(document.createTextNode("There was an error loading this information."));
       });
       });
     })();
     })();

Revision as of 01:08, 24 January 2025

This widget uses the MediaWiki API to request a list of pages within a category, and spits them out into a div. It takes one parameter, which is the category name. This is done on the client side, using JavaScript, which is less than ideal. It can only be used once on a page. It is currently only used by Template:Location Tools.

Example

{{#widget:CategoryPages|category=Tools and Equipment in Electronics Area}}

Parameters

category
The name of the category.