Jump to content

Cloning Fields that are already in use


torf
 Share

Recommended Posts

I have no idea if that is even possible, but I run into a problem with planning ahead the structure every now and then:

If I have multiple templates that use the same field I try to reuse my fields of course. So let's say I have the field: myPictures (Images / jpg / max 5 images / ...). I use that field with different descriptions in multiple Templates. Now the site is in use, and after some month the client decides that in one template there need to be 8 possible upload slots with only png allowed. Now I'm stuck.

If I change the field it changes for all, if I make a new field I loose all the uploads that already have been made for this template, if I'm going the safe way and add different fields for every template from the beginning I get to many fields that are maybe never needed.

Is there any solution for that problem?
 

Link to comment
Share on other sites

I would add a new field with your requirements and migrate the contents from the "old" to the "new" field. Here is how I did it for a migration from a single image ("image") to a multiple images ("images") field:

$gearPages = $pages->find("template=products-view-gear, include=all");
foreach($gearPages as $p) {
    if($p->image) {
        $p->of(false);
        $p->images->add($p->image);
        $p->save();
    }
}

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, torf said:

Now the site is in use, and after some month the client decides that in one template there need to be 8 possible upload slots with only png allowed.

You don't need a different field for this scenario. You can use template overrides for the field settings.

In the field settings (Overrides tab):

image.png.9fd0018c6bdb55a1411c0325d68ef3e7.png

Then from the template settings, edit the field in template context:

image.png.5c5247240a005fc8d8c22b3c74099ced.png

 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...