keithmancuso / craft-json-expand

a simple twig filter for Craft CMS to output entry models into json
http://familiar.is
23 stars 1 forks source link

Asset objects aren't returned with all attributes set #1

Open imjakechapman opened 9 years ago

imjakechapman commented 9 years ago

I'm spitting back a single entry via the json_expand | raw twig function for Marionette to digest on initial page load.

This is the object that is given back for the entries mp3...

This field is attached to a matrix field that only allows 1 mp3 fields to be entered. The only available attributes is the slug.

"mp3":{ "0":{ "id":"5", "enabled":"1", "archived":"0", "locale":"en_us", "localeEnabled":"1", "slug":"thinkcraftcode-demo", "uri":null, "dateCreated":{ "date":"2014-04-04 08:13:30.000000", "timezone_type":1, "timezone":"+00:00" }, "dateUpdated":{ "date":"2014-04-04 08:41:21.000000", "timezone_type":1, "timezone":"+00:00" }, "root":null, "lft":null, "rgt":null, "level":null, "sourceId":"2", "folderId":"2", "filename":"thinkcraftcode-demo.mp3", "originalName":null, "kind":"audio", "width":null, "height":null, "size":"1488687", "dateModified":{ "date":"2014-04-04 08:13:28.000000", "timezone_type":1, "timezone":"+00:00" } }

But spitting it out with normal twig inside of a template gives me the full URI, not just a filename.

imjakechapman commented 9 years ago

Just a quick update. This only happens when it's a matrix field asset. :smiley:

keithmancuso commented 9 years ago

hey jake, sorry for the issues. To be honest we sort of moved away from using this plugin internally for a number of reasons, the biggest of which was performance, since it was designed to output the entire object it really turned out to be really really slow.

For our internal projects we actually started using https://github.com/nfourtythree/craft-json-data which allows you to specify fields vs dumping the entire object. Nathan and I traded a lot of notes back and forth as were working and he ended up with a better approach i think.

I should also say the technique we've had the most success with is simply writing out the json in a template more like this: http://craftcms.stackexchange.com/questions/20/how-would-i-retrieve-channel-data-in-json-format/60#60

The last thing i'll share is you may also want to look at https://github.com/mattstauffer/craftcms-prune it seems to work a lot like Nathans json data plugin but just focused on filling out the object fields and using the standard | json_encode filter

I hope some of that helps