Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Using a Loop for Creating Custom Fields

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 825 Views
  • juneallison
    Avatar
    Community Member
    108 Posts

    Using a Loop for Creating Custom Fields Link to this post

    Hi,

    I have to create a large number of custom fields for a specific page template. I understand how to create these custom fields manually (one by one) and make them appear in the admin area.

    Is it possible to have/create a for or while loop that will create these custom fields?

    And suggestions or code examples would be greatly appreciated!

    Thank you!

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Using a Loop for Creating Custom Fields Link to this post

    No you can't. All fields need to be declared in a static array. If you are in a position of needing lots and lots of fields then you should be looking at creating a datamodel that supports that. E.g create a DataObject to handle your field and attach it to a page using a 'has_many'. Tutorial 5 has information about relationships - http://doc.silverstripe.org/sapphire/en/tutorials/5-dataobject-relationship-management.

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Using a Loop for Creating Custom Fields Link to this post

    @Willr - Thanks for your reply and pointing out the tutorial!

    I'm going to have to read this tutorial a couple more times. In the mean time I wanted to ask a question about what I am specifically looking to do. I think what I need to accomplish might have one more level to it than this tutorial demonstrates.

    Basically I have a page type that can have up to 6 mini galleries. I've already created this page and have used the (static) custom field approach to create fields for the title and description of each gallery. On the page template side of things a gallery area will only show if the gallery title is filled in.

    So each mini gallery can have up to 12 images. Each DataObject(?) needs to have a thumbnail, large image and a caption. I'm not using any kind of gallery module. I'm using some jquery scripts to show thumbnails that open in lightboxes and all of the thumbnails are contained in a slider. I just need away to allow the admin to add images to each mini gallery. And then I need to be able to output these images.

    So just thinking outloud, setting up the Image DataObject will be like setting up a student ...Thumbnail, large image and Caption instead of First Name, Last Name and Nationality. And in some sense a mini gallery will be like a Mentor ...where it can have numerous images associated with it.

    I guess where I'm getting stuck is how to associate each mini gallery to a page, allow a page to have more than one mini gallery and link the mini galleries to their corresponding gallery area that already exists. (or can potentially exist). For instance the current page template has custom fields GalleryTitle01, GalleryDescription01, GalleryTitle02, GalleryDescription02, etc. (up to 6). A single gallery area will output GalleryTitle01, GalleryDescription01 and the corresponding mini gallery.

    Any feedback you are willing to share on this would be great. Thank you!

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Using a Loop for Creating Custom Fields Link to this post

    And just to think out loud again.... Above I think I'm basically saying:

    An Image Object (thumbnail, image, caption) needs to be associated with a single mini-gallery. A mini-gallery needs to be associated with a page and a specific area of that page (one of the 6 gallery areas).

    Thanks!

    825 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.