Hack Job


The primary reason for this extension is to control the fields being output to json_encode. It is very useful for generating a json output from twig template data. If you need an api for consuming externally, or even internally via Javascript frameworks such as Vue.js, React or Angular with Axios or other http libraries, this will make it easy for you.

This template will get all entries from the "news" section, grab just the title and body fields from each, and then output it to JSON.

{{ craft.entries.section('news').find() | hackjob(['title', 'body']) | json_encode() | raw }}

This template will get output a json array of all selected users and display the user fields and custom fields associated with their profile.

{% set users = craft.users.group('members').all() %} {{ users | hackjob(['id', 'username', 'name', 'email', 'photoUrl', 'customFieldOne', 'customFieldTwo']) | json_encode() | raw }}


Free

Package Name

To install this plugin, search for its package name on the Plugin Store and click “Install”.


Information

  • Version 1.0.0
  • Last Update 11/17/2018
  • Active Installs 8
  • Compatibility Craft 3
  • License MIT
  • Categories Templating

Report an issue