Jump to content

Module:PrinterInstructionsLookup/doc

From Swarthmore Knowledge Base
Revision as of 14:49, 14 May 2026 by Aruethe2 (talk | contribs) (Created page with "{{Module rating|protected}} This module handles the conditional inclusion of printing instruction templates on printer pages, based on the printer's model, access permissions, and print release station status. It is invoked by Template:Printer. == Usage == This module is not intended to be called directly. It is invoked from within the Printer template using: <syntaxhighlight lang="wikitext"> {{#invoke:PrinterInstructionsLookup|getInstructions}} </syntaxhighlight...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:PrinterInstructionsLookup

Template:Module rating

This module handles the conditional inclusion of printing instruction templates on printer pages, based on the printer's model, access permissions, and print release station status. It is invoked by Template:Printer.

Usage

This module is not intended to be called directly. It is invoked from within the Printer template using:

{{#invoke:PrinterInstructionsLookup|getInstructions}}

The module reads its inputs from the parent template's parameters, so it must be invoked from a template that has the relevant parameters defined.

Parameters Read

The module reads the following parameters from the parent template:

Parameter Type Description
Printer Model String The full model name of the printer (e.g., "Canon imageRUNNER 2630", "HP LaserJet 4555", "Dymo LabelWriter 450"). Matched case-insensitively against known brand names.
Access Comma-separated list Who is permitted to use the printer. Recognized values: Employees, Students. Multiple values may be supplied, separated by commas.
Print Release Station Boolean Whether the printer has a print release station. Truthy values: Yes, yes, true, 1, on (case-insensitive). Any other value is treated as false.

Logic

The module evaluates each of the following conditions independently and appends the matching template to the output. A single printer may trigger multiple inclusions.

Condition Template Included
Printer Model contains "Dymo" {{Printing Instructions for Dymo LabelWriter}}
Printer Model contains "Canon" AND Access includes "Employees" {{Printing Instructions for Employees - Canon}}
Printer Model contains "HP" AND Access includes "Employees" {{Printing Instructions for Employees - HP}}
Printer Model contains "Canon" AND Access includes "Students" {{Printing Instructions for Students - Canon}}
Printer Model contains "HP" AND Access includes "Students" {{Printing Instructions for Students - HP}}
Print Release Station is truthy {{Print Release Station Instructions}}

Brand matching is case-insensitive and uses substring matching, so "canon imagerunner" and "Canon imageRUNNER" both match the Canon condition.

The Dymo condition does not depend on the Access value — Dymo instructions are included for any printer with "Dymo" in the model, regardless of who can use it.

Output

The module returns wikitext containing the matched template inclusions, joined by newlines. The output is preprocessed via frame:preprocess() so that template calls are expanded rather than appearing as literal text.

If no conditions match, the module returns an empty string.

Functions

getInstructions(frame)

The single entry point of the module. Reads parameters from the parent frame, evaluates all conditions, and returns the assembled wikitext.

Parameters
frame — The Scribunto frame object. The module calls frame:getParent().args to access the invoking template's parameters.
Returns
A string of wikitext containing zero or more template inclusions.

Adding a New Brand

To add support for an additional printer brand (for example, Brother):

  1. Create the relevant instruction template(s), such as Template:Printing Instructions for Employees - Brother.
  2. Edit Module:PrinterInstructions and add a detection line near the existing brand checks:
    local hasBrother = mw.ustring.find(modelLower, 'brother', 1, true) ~= nil
    
  3. Add the corresponding conditional blocks alongside the Canon and HP ones:
    if hasBrother and hasEmployees then
        table.insert(output, '{{Printing Instructions for Employees - Brother}}')
    end
    

No changes to the Printer template are required.

Adding a New Access Type

To add a new access type (for example, "Guests"):

  1. Update the Printer template's Access parameter to accept the new value (in the <templatedata> block and any forms).
  2. In the module, add a lookup line near the existing ones:
    local hasGuests = accessSet['Guests'] == true
    
  3. Add the conditional blocks for the brand/access combinations you want to support.
  4. If a new category is needed, add it to the #arraymap / #switch block in the Printer template.

Debugging

To inspect the values the module is receiving, temporarily add a debug return at the end of getInstructions, before the final return frame:preprocess(result):

return 'Model: "' .. model .. '" | Access: "' .. access 
    .. '" | PrintRelease: "' .. printRelease .. '"'
    .. ' | Canon: ' .. tostring(hasCanon)
    .. ' | HP: ' .. tostring(hasHP)
    .. ' | Dymo: ' .. tostring(hasDymo)
    .. ' | Employees: ' .. tostring(hasEmployees)
    .. ' | Students: ' .. tostring(hasStudents)
    .. ' | PR: ' .. tostring(hasPrintRelease)

This will replace the normal output with a diagnostic string showing what the module parsed from the parameters. Remember to remove the debug line once finished.

Dependencies

  • Extension:Scribunto — required to run Lua modules.
  • Template:Printer — the template that invokes this module.
  • The instruction templates referenced above. Missing templates will produce red links in the rendered output.

See also