from typing import Dict
from typing import Any


def modify_namelist_template(
        namelist_template: str,
        placeholder_dict: Dict[str, Any]
):
    """
    Placeholders in the form of %PLACEHOLDER_NAME% are replaced within the
    given namelist template.

    Parameters
    ----------
    namelist_template : str
        Placeholders within this template are replaced by the given value.
    placeholder_dict : Dict[str, Any]
        This is the directory with the placeholder values. A placeholder is
        skipped if it is not found within given namelist template. The values
        have to be castable to string type.

    Returns
    -------
    namelist_template : str
        The namelist where the placeholders are replaced with given values.
    """
    for placeholder, value in placeholder_dict.items():
        namelist_template = namelist_template.replace(placeholder, str(value))
    return namelist_template