Skip to content

Allow for nested field types (entries, matrix, etc) #2

@timkelty

Description

@timkelty

Just making an issue here to brainstorm.
I was playing around with the best way to approach this and was first considering how we'd want it to look from the template side.

Option 1:

Make the fields param a hash.

  • true would indicate just returning the value.
  • a hash would indicate this field had nested data (e.g. matrix or entires), and which fields or columns to get.
  • a true instead of a map on an entries field could return an array of IDs.
  • a true instead of a map on an matrix field could return a hash of every column and it's value.
{{ craft.entries.section('news').find() | prune({
  'id': true
  'title': true,
  'myEntriesField': {
    'id': true,
    'otherField': true,
    'myNestedMatrixField': true, 
  },
  'myMatrixField': {
    'myCol': true,
    'myEntriesCol': {
      'id': true,
      'title': true,
    }
  },
  'myOtherEntriesField': true
}) | json_encode() | raw }}

Option 2:

Add a 3rd mappings param, with the keys of the field and the value of the fields/columns you want.

{{ craft.entries.section('news').find() | prune(
  ['id', 'title', 'myEntriesField', 'myMatrixField', 'myOtherEntriesField'], {
  'myEntriesField': ['id', 'otherField', 'myNestedMatrixField'],
  'myMatrixField': ['myCol', 'myEntriesCol'],
  'myEntriesCol': ['id', 'title'],
}) | json_encode() | raw }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions