wheelmaker24

New Template Family Setting: Single Child

Recommended Posts

Hi,

I got a new idea which come in handy when creating ProcessWire pages with enclosed subsections. Currently within the template family settings there is a setting "Can this template be used for new pages?" with the options "Yes", "No" and "One". My proposal is to add a fourth option that is "Single Child". This would allow the template to be created only once within another page (meaning that there wouldn't be any siblings with the same template).

To give you an example look at this page structure for a multi-site webpage:

  • Newsroom root
    • Newsroom for Country 1
      • News articles
        • Article 1
        • Article 2
        • ...
      • Tags
      • Search
      • 404
    • Newsroom for Country 2
      • News articles
      • Tags
      • Search
      • 404
    • Newsroom for Country 3
      • ...

The root template will automatically redirect to the country newsroom page according to the browser's locale settings. Within each country newsroom there should obviously only be one "Tags", "Search" and "404" template. The option mentioned above would enable me to do this.

A work-around solution for my specific use-case would be to select the option "No" and automatically create the Country Newsroom's children via a hook that triggers when a new country newsroom page has been created. But I think that this fourth option could come in handy for other use-cases as well.

What do you think?

Share this post


Link to post
Share on other sites

Don't disagree with 'one' being an option, but what about rather than 1, having an integer? You might want exactly 3 children for a particular requirement.

Share this post


Link to post
Share on other sites

I may be wrongly interpreting this as a quite specific need, but I'd make this feature a module. I've never needed something like this but who knows, maybe one day. So it makes sense to me to keep this out of the core, and something we could add as a module when we need it.

  • Like 1

Share this post


Link to post
Share on other sites

While I agree that Dave's statement might be a very specific need, I think that both "One" and "Single Child" options have their purposes. Besides the use-cases mentioned above, you could use it for the following:

  • A "config" page for specific pages (e.g. when having a portal with sub-portals you could add a "config" page as a child to each sub-portal and there configure theme, navigation, ...):
    • Sub Portal 1
      • Config Page
      • Page 1
      • Page 2
      • ...
    • Sub Portal 2
      • Config Page
      • ...
    • Sub Portal 3
    • ...
  • When using a folder strategy for the page tree, you could use it for sub-pages like "Attachments", "Comments", ... that may be added once to every page without canibalizing the page hierarchy, e.g.
    • /page1/
    • /page1/comments/
    • /page1/attachments/
    • /page1/subpage1/
    • /page1/subpage/1/comments/
    • /page1/subpage2/
  • When having a registration system with the following page structure, "Events" and "Registrations" pages should have the "Single Child" option enabled:
    • Conference 1
      • Events
        • Event 1
        • Event 2
        • ...
      • Registrations
        • User 1
        • User 2
        • ...
    • Conference 2
      • ...
    • Conference 3
    • ...

Share this post


Link to post
Share on other sites

Thinking about it some more... As an alternative to "Single Child", you could also use "One per parent"

Share this post


Link to post
Share on other sites

This feature sounds like it would be a prime candidate to add to the admin on steroids module.

Share this post


Link to post
Share on other sites

If anybody wants to steal some code (or use that little module as is, of course), feel free... :)

  • Like 8
  • Thanks 1

Share this post


Link to post
Share on other sites
2 hours ago, gmclelland said:

Thinking about it some more... As an alternative to "Single Child", you could also use "One per parent"

You are right, this is a better name!

Share this post


Link to post
Share on other sites
2 minutes ago, BitPoet said:

If anybody wants to steal some code (or use that little module as is, of course), feel free... :)

Wow! That was quick :)

Will try it out tomorrow!

Share this post


Link to post
Share on other sites
19 minutes ago, BitPoet said:

If anybody wants to steal some code (or use that little module as is, of course), feel free... :)

DAMN! I'm gonna mention this to a client someday.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sten
      Hi,
      I have a lot of difficulties with getting a field value.
      First I created a template, inside I created several fields
      two fields are a dropdown select box So I have a value and a label for each line.
      Then I want to get the field value in _init.php or in the template to display it. How can I get the value of a field for the page ? I need to understand the flow through which data goes.
      Could someone help me ?
      Thank you
       
       
       
    • By louisstephens
      So this is more or less just a question regarding best practices, and how to actually achieve this. I have an internal tool I built awhile ago that has just gotten very "trashed". The naming conventions are all out of whack due to trying to get something completed, and pages are just everywhere. The fields got really out of hand as well, but I believe I have found a much cleaner field structure with the Repeater Matrix and a few other ProFields.  I decided recently to rewrite the template structure and the fields from scratch to keep everything nice and neat, but then it hit me that I would need to move all the previous data over and populate the new fields etc.
      The current tree looks something like:
      Group Title - Section A (template "section") - Category One (template "category") - Category Two (template "category") - Section B (template "section") - Category One (template "category") - Category Two (template "category") Etc etc... The structure is pretty good, and I am thinking of keeping it as it serves my purpose. However, I now have about 140 Sections with child pages that I would hopefully like to move to different templates, as well as changing the child templates/mapping data to the new fields. The only fields I need to worry about are a few textareas, text fields, options field,  as well as 1 image filed.
      I guess my real question is, what is the best way to go about this "migration" via the api while keeping the parent/child structure. It would be ok to leave it as is and chip away at it if I were the only one using it, but unfortunately that is not the case. 
      I guess one approach would be to copy over the entire structure and make the move to the new templates/fields. Once we have verified all the data/templates are correct, we could remove the old structure and possibly rename the new to mirror the old. However, this might just be too complicated.
    • By louisstephens
      So I have a project where multiple pages are sending POST data to 1 single template page.  All was working well (well, at least with one ajax post), but now I have hit a stumbling block. I figured  the "best" way to handle the request were to use url segments and then use the following in the status page:
      if ($config->ajax && $input->urlSegment1 == 'add-bookmark') { // some code here } However, this doesnt seem to really work (as I assume the the request isnt being posted to /status/ but rather to /status/add-bookmark/). What is the best way to actually handle this?
    • By louisstephens
      Currently, I have a page set up listing all child pages using a foreach loop and outputting some information (thus far, it is all gravy). However, I ran into a slight problem. I have a "button" on each item being rendered that when clicked needs to send the page id to another page for processing via ajax. I thought I could just save the item id like :
      <?php $itemId = $item->id; ?> And then encoding it below in my javascript:
      var itemId = <?php echo json_encode($itemId); ?>; var data = { itemId: itemId, }; $.ajax({ type: "POST", url: "/intra/status/", data: data, success: function(){ console.log(itemId); } }); However, it is only posting the last page's id rendered by the foreach. Have I just overlooked something simple on this?
    • By dweeda
      How do I migrate a template with all its fields and values to a new site? Is their an export/import process?