Can I assign a template to a param somehow in dml?

55 views Asked by At

I have those templates:

template some_template {
    param some_param default false;
}

template another_template {
    param some_param default false;
}

And I want to process templates like this:

param templates_to_work_with = [some_template, another_template];

in each (each in (templates_to_work_with)) {
    param some_param = true;
}

Or, at least, like this:

param templates_to_work_with = [some_template, another_template];

method set_true() {
    foreach tmpl in (templates_to_work_with) {
        tmpl.some_param = true;
    }
}

But I've got compilation error obviously:

In templates_to_work_with
error: unknown identifier: 'some_template' 

How can I get through it? Any ways to make this processing in dml?

1

There are 1 answers

0
Erik Carstensen On

Templates are not values or even expressions, so cannot be part of parameters.

I suppose your use case is that in each ... { param some_param = true; } is part of a library, and param templates_to_work_with = [...]; belongs to the user of that library? If so, then I think the best your library can do is:

template some_property {
  param some_param = true;
}

and then let the user say:

in each some_template { is some_property; }
in each another_template { is some_property; }