Keystone-classic: Are underscore methods available on Types.CloudinaryImages? If so, how do you use them?

Created on 12 Mar 2016  Â·  10Comments  Â·  Source: keystonejs/keystone-classic

Most helpful comment

See the CloudinaryImages doc:

"Stores multiple images in a array as a nested Schema, each of which expose the same methods as the cloudinaryimage field."

So you can loop over your CloudinaryImages array and call whatever underscore method you want on them:

yourModel.images.forEach(img => {
  img.crop(200, 200);
});

All 10 comments

There are a bunch of them available, check the Underscore methods section of the Cloudinary Image doc!

src(options) String - returns the url of the image, accepts all options cloudinary supports

tag(options) String - returns an <img> tag

scale(width, height, options) String - scales the image to fit the exact width and height, retaining aspect ratio

fit(width, height, options) String - scales the image to fit within the specified width and height, retaining aspect ratio

lfit(width, height, options) String - scales the image to fit within the specified width and height, retaining aspect ratio (without exceeding the original dimensions)

limit(width, height, options) String - scales the image (down only) to fit within the specified width and height, retaining aspect ratio

fill(width, height, options) String - scales the image to fill the specified width and height

crop(width, height, options) String - crops the image to fill the specified width and height

pad(width, height, options) String - pads the image to fill the specified width and height

lpad(width, height, options) String - pads the image to fill the specified width and height (without exceeding the original dimensions)

thumbnail(width, height, options) String - crops the image to fill the specified width and height

Um... for CloudinaryImage, yes. For CloudinaryImages, no. I couldn't figure out how to access the methods from the image array. Show me an example and I'll believe you. 

See the CloudinaryImages doc:

"Stores multiple images in a array as a nested Schema, each of which expose the same methods as the cloudinaryimage field."

So you can loop over your CloudinaryImages array and call whatever underscore method you want on them:

yourModel.images.forEach(img => {
  img.crop(200, 200);
});

Is it possible to have this added to the documentation? I think it would really help people searching for it.

We plan on rewriting the documentation for/maybe after the 0.4 release to be more user friendly. Right now it's great if you're developing keystone itself, but not so great if you're using keystone to develop a website.

We plan to change that – if you want to help check out: https://github.com/keystonejs/keystonejs-site

So what ? It is really non understandable how to use it in model. At least, give any docs for read about configuration it on model. It will be very useful.

I still can't use underscore methods for cloudinary images
trying

product.images.forEach(function(img) {
      console.log(img.tag()); //tag is not a function
});

'4.0.0-beta.7' Underscore methods aren't working anywhere, including Cloudinary

Image underscore methods aren't working:

player model

[...]
Player.add(
'test',
{ photos: { type: Types.CloudinaryImages } },
[...]

players.twig

[...]
{% for player in data.players.results %}
  {% include 'player_item.twig' with {p: player} %}
{% endfor %}
[...]

player_item.twig

[...]
<img src="{{ p.photos[0].limit(92,92) }}">
[...]

@mxstbr Still cannot use underscore method. In keystone version 4.0.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joernroeder picture joernroeder  Â·  5Comments

sorryididntmeantto picture sorryididntmeantto  Â·  3Comments

sarmadsangi picture sarmadsangi  Â·  5Comments

schybo picture schybo  Â·  3Comments

koenoe picture koenoe  Â·  4Comments