3

I have a few fields assigned to an Asset Source, which allow the user to alter the appearance of the image (large, small, portrait, landscape) etc. on the front end.

I'm not sure if this is a bug or intended behaviour, but when I enter a field value as an editor to a particular instance of an Asset, if that Asset then appears elsewhere in a different entry, it appears to inherit the field values of the Asset where it was used previously.

I need to be able to have an image in one entry set to, for example, 'large', but also have that same image appear on another entry but set to 'small'.

Assuming this is intended behaviour, how can I get around this?

2

The fields attached to an asset source will be connected to the asset, and will follow the asset no matter where it's used. So yes, this is the intended behavior.

If you need to specify on an entry basis what size an image should have, you need to add a field for selecting size on the entry type. Say you have a field "Main image" in your entry type, you'd add a "Main image size" field to the same entry type.

If you're making a gallery or something, instead of having one assets field where you select all images, you could create a matrix field that has one column for (one) asset and one column for size instead, and add each image as it's own row.

| improve this answer | |
  • Thanks Andre, this is good to know, and highly disappointing. In EE I would have done as you suggest, but since in the case mentioned I'm not creating a gallery, but a series of different entry types that can be combined by the editors in a single template to create very customisable layouts including text and groups of images. Being able to adjust the image positions etc via Asset fields keeps things clean and intuitive in the editing panel. – pumkincreative Oct 15 '14 at 21:06
  • I see. So you're creating some sort of long-form articles/one-pagers? How are you using entry types for this? Wouldn't a Matrix field be better suited? – André Elvan Oct 15 '14 at 21:16
  • I decided that Matrix wasn't practical in this case as there are a fair few fields per type. The model of multiple entry types per section works well for this particular application. Also if I was to use Matrix then I wouldn't have the option to fall back on that to provide unique fields per Asset instance (afaik you can't nest Matrix fields, right?). I am therefore allowing the editors to build up a long single page by adding different entry types within a Structure section. – pumkincreative Oct 15 '14 at 22:01
  • You might also check out the supertable plugin, which can be used in combination with matrix fields to create more complex layouts. In the past I have also created a separate channel called 'partials' (or 'sections' or 'modules' or whatever) and used a matrix field in my main 'pages' structure to create relationships to the partials. This has the advantage of allowing partials to be reused throughout the site as needed. – Douglas McDonald Apr 18 '16 at 6:03
1

To be clear, you're using image transforms to control the size of your image, correct?

André is correct... If your image manipulation fields will have different values per entry, then those fields should be attached to the entry type, not the asset source.

So your entry type would contain these fields:

  • Image
    • "Assets" fieldtype
    • limit 1
  • Image Size
    • "Dropdown" fieldtype
    • options: "Small", "Medium", "Large"

Your template would look something like this:

{% set asset = entry.image.first %}
{% set transformSize = entry.imageSize.value %}

<img src="{{ asset.getUrl(transformSize) }}" width="{{ asset.getWidth(transformSize) }}" height="{{ asset.getHeight(transformSize) }}">

The person editing the entry can easily select which asset and what size.

| improve this answer | |
  • Thanks Lindsey, yes I understand this way of doing it, it just seems to me that the usefulness of the fields is reduced if they relate to Assets and not instances of Assets. I would argue that it's also a little counter-intuitive given that you can edit these fields from the Entry page. Anyway I'm probably just grumbling because I didn't realise this and now I've got to change several structures to work as Matrix fields instead of standalone Asset fields. – pumkincreative Oct 17 '14 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.