def replace_value(value, arguments, parameters):
    """Test whether the string is a reference to a template parameter and (if
    True) replace the value with the given argument or default value.

    In the current implementation template parameters are referenced using
    $[[..]] syntax.

    Parameters
    ----------
    value: string
        String value in the workflow specification for a REANA template
    arguments: dict
        Dictionary that associates template parameter identifiers with
        argument values
    parameters: dict(reana_template.parameter.TemplateParameter)
        Dictionary of parameter declarations for a REANA template

    Returns
    -------
    string
    """
    # Check ff the value matches the template parameter reference pattern
    if value.startswith('$[[') and value.endswith(']]'):
        # Extract variable name. If arguments contains a value for the variable
        # we return the associated value from the dictionary. Otherwise, the
        # parameter default value is returned
        var = value[3:-2]
        if var in arguments:
            return arguments[var]
        return parameters[var].default_value
    else:
        return value