If the dashboard you are importing does not yet have a template variable for the datasource, then yes, indeed you will have to modify it to add such a template variable (
https://grafana.com/docs/grafana/latest/variables/variable-types/add-data-source-variable/).
Another situation is if you use a system like Thanos to get an aggregated view over multiple Prometheus servers. In that case, the returned data would contain the external labels of each server. If you then wanted to narrow down the data to only a specific server, you could add label matchers in PromQL (potentially with template variables again) for that server's external labels.