Jump to content

Duplicate field settings when creating a new one


vknt
 Share

Recommended Posts

Hi all,

When making a new template you can tell it to duplicate fields from another template. Can we do the same for fields? I spend alot of time configuring fields that are just a 1 setting different than another one I already have

e.g. I love the description on fields. It really helps if I can type something in there to tell what the field does. But e.g. images on 1 page is doing something else on another page. That makes i have to create 2 with only a different description. That is why a duplicate would be useful for me among other things..

Link to comment
Share on other sites

  • 1 month later...

This has been added in the latest commit of the 'dev' branch (for 2.2). You'll see the Field duplicate/clone option under the 'advanced' menu when editing a field. From there, you just check the box asking you if you want to clone the field and click save.

You can also access it from the API like this:

<?php
$field = $fields->get('title'); 
$clone = $fields->clone($field); 

The new field that is returned ($clone) has already been saved, so you don't need to save it again.

Also note that it automatically assigns a new name to the field to ensure it's unique. Like with cloned pages, it adds an incrementing number to the end of the name:

<?php
$clone = $fields->clone($field);
echo $field->name; // would print 'title';
echo $clone->name; // would print 'title_1'; 

You can of course go back and rename it to whatever you want.

<?php
$clone->name = 'something_else';
$clone->save();

Template duplicate/clone

An identical clone() function was also added to the template editor. You'll see it in the 'advanced' menu when editing any Template. When you clone a template, the Fieldgroup is cloned and the template-file is also cloned if /site/templates/ is writable.

Using it in the API is exactly the same as with cloning a field, and the behavior is exactly the same:

<?php
$template = $templates->get('basic-page'); 
$clone = $templates->clone($template);

  • Like 1
Link to comment
Share on other sites

  • 3 years later...

This has been added in the latest commit of the 'dev' branch (for 2.2). You'll see the Field duplicate/clone option under the 'advanced' menu when editing a field. From there, you just check the box asking you if you want to clone the field and click save.

At my current PW version 2.6.3 the duplicate/clone option moved to the 'action' menu.

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...