How to access meta from macro

I have below in schema.yml

models:
  - name: my_model
    meta:
      foo: 1234

How to get the foo value from macro? Ideally I expect the macro has this , and from this I can get the foo value.

to access the foo value from a model u can use {{ model.meta.foo}} in a model file

to access it from macro we have to use the graph jinja variable and filter for models,
if you want to access only for a particular model you have to write another filter condition how i have written for models using the selectattr in the below macro

{% macro get_meta_fields() -%}

{% if execute %}
  {% for node in graph.nodes.values()
     | selectattr("resource_type", "equalto", "model") %}
    {% do log("Model: "~ node.name ~ "   " ~ node.meta, info=true) %} /* this will print meta fields set to a model as a dictionary */
    {% do log("Model: "~ node.name ~ "   " ~ node.meta.foo, info=true) %} /* this will print value set to the foo field */
  {% endfor %}
{% endif %}

{%- endmacro %}
1 Like

Thanks. I followed this and made it work!

1 Like

Please what if I want to limit my desired values to my_model value from the name key?

Note: @odunayo.rotimi originally posted this reply in Slack. It might not have transferred perfectly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.