Skip to content

Feature proposal: Creating multiple template parameters from a dict #319

@eseiver

Description

@eseiver

Currently, when creating a Template object with multiple parameters, users need to call template.add() separately for each name-value pair.

    param_dict = {
        'foo': 'bar',
        'eggs': 'spam',
    }
    template = mwparserfromhell.nodes.template.Template('name')
    for k, v in param_dict.items():
        template.add(k, v)

This process can be tedious and less efficient, especially when dealing with a large number of parameters.

Proposed solutions:

  1. Direct dictionary passing
    Allow users to pass the parameters as a dict directly when creating a Template object.
    param_dict = {
        'foo': 'bar',
        'eggs': 'spam',
    }
    template = mwparserfromhell.nodes.template.Template('name', params=param_dict)
  1. Bulk addition method
    Introduce a new method in Template, such as add_all(), to allow adding multiple parameters at once using **kwargs.
    param_dict = {
        'foo': 'bar',
        'eggs': 'spam',
    }
    template = mwparserfromhell.nodes.template.Template('name')
    template.add_all(**param_dict)

Benefits:

  • Simplified handling of template parameters
  • More flexibility and convenience in working with Template objects

I'd be happy to start working on a PR for this, but wanted to get feedback from the community first before proceeding to implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions