Jump to content

Clone field or field group


neotoxic
 Share

Recommended Posts

Setting up multiple filed for the same page is a long winded task. For example my template has 4 sections each with a title, image, description and url. creating these 4 boxes requires 16 fields to be set up and configured and then added to the template. To make the admin page clearer I have set them up in field groups which means I now need to create and configure 20 new fields.

As the configuration for the first text filed for example, will be identical to the other 3 it would be a great aid to this task if the admin interface would allow you to clone fields. and simply supply and alternate name.

Link to comment
Share on other sites

Hi neotoxic,

I'm not 100% sure on what you are trying to accomplish, but this may help. You have a template file with four sections in it. You also have four fields in that template. If you create four sub-pages of the same page template and loop through them, you can easily populate the four sections in the first template.

I'll try to illustrate this a bit.

Create a template named section. Give it the four fields (title, image, description, url). Create a Page called Main Section. and give set it to the section template. Add four sub-pages to the Main Section and give them the same template.

In your template php file, try this code:

<?php
$count = 1;
foreach($page->children() as $child)
{
echo "Section " . $count. "<br />";
echo $child->title . "<br />";
echo $child->url . "<br />";
}

This may shed some light on the uses of ProcessWire. Sub-pages can easily be treated as a single page - you can just use those sub pages as basic information. I can explain further if you need.

-Jim

Link to comment
Share on other sites

Hi neotoxic,

I second Jimyost at thinking this might not be actually real place for 'new function', but rather reconsidering data model for your templates. If you wish, we may close this up and you may add us some new thread in 'API & templates', so some of us with (maybe) more experience with PW2 might help you adjust what you want to accomplish.

Link to comment
Share on other sites

One other possible workaround is to re-purpose the existing image description field. Setup a multi-image field and set it's description field to have 4 rows. Then assume that the first line is always the title, second line always the URL, and any remaining lines are the description.

<?php
foreach($page->images as $image) {
    $lines = explode("\n", $image->description); 
    $title = trim($lines[0]);
    $url = trim($lines[1]); 
    unset($lines[0], $lines[1]);
    $description = implode("\n", $lines); 
    // now your $title, $url and $description fields are ready to use.
}

Like I say, it's a workaround, but it would solve this particular case. This could be improved upon, but this is just a simple example.

Link to comment
Share on other sites

  • 2 weeks later...

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