Jump to content
joer80

Adding children to user template

Recommended Posts

I am trying to add a child page to a user and I am getting an error.  Enabled the user template to have children but when I add a child page there is an error.  Does anyone have any ideas?

The error is: "The template 'user' does not allow parents of type 'user'" but it never lets me select the template I allowed.

Thanks!

Screen Shot 2019-03-24 at 11.17.20 PM.png

Screen Shot 2019-03-24 at 11.17.07 PM.png

Share this post


Link to post
Share on other sites

Hi @joer80,

1. Go the Setup --> Templates, click Filters. Then set "show system templates" to Yes.

2. Click "user" template

3. click Family tab

4. set "May this template has childern" to Yes.

5. set templates allowed for this template if necessary.

But please think twice before you do this. It is not encouraged to add children to user page. It is better to create a separate page with page reference field that set to choose from user pages.

Gideon

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, Gideon So said:

Hi @joer80,

1. Go the Setup --> Templates, click Filters. Then set "show system templates" to Yes.

2. Click "user" template

3. click Family tab

4. set "May this template has childern" to Yes.

5. set templates allowed for this template if necessary.

But please think twice before you do this. It is not encouraged to add children to user page. It is better to create a separate page with page reference field that set to choose from user pages.

Gideon

I enabled the user template to have children of the correct template but it does not allow it to have children.  It just gives the error I posted.  I am wondering if it is a bug. 

In this situation I want to allow users to attach Licenses to their user accounts.  Each will have 4 fields or so and they can have a number of them.  It would make sense to me to store them as children.  If this is not possible I may need to make a hidden page at root to store them under?  Or maybe do a repeater?

Share this post


Link to post
Share on other sites
23 minutes ago, joer80 said:

may need to make a hidden page at root to store them under?  Or maybe do a repeater?

Yes, why not?

Or you could add a new field for licenses to the user template, and store the infos directly there?

Share this post


Link to post
Share on other sites

I was not aware that it is discouraged to put children under user pages.  What is the reasoning?  I am curious if the same reasoning would apply to using a repeater on user pages or are they encouraged?

I can do a hidden page at home if both are discouraged but I would rather not since there is the chance of things becoming out of sync. 

ie. If you delete a user manually, it is not going to automatically delete the hidden root pages that belong to him that are detached.

Share this post


Link to post
Share on other sites
6 minutes ago, joer80 said:

I was not aware that it is discouraged to put children under user pages

I guess it has to do with security. Since the user is a system-template, there are mechanisms (limitations) in place that potentially try to stop you from doing something that may sooner or later break stuff.

Share this post


Link to post
Share on other sites

It's odd: If you try to add a child-page under Access > Users > usernameX > Tab "Children", you get these errors as posted above.

However, you can create child-pages via the page-tree without a problem!

user-child-pages.PNG.38d1ffd0bfab7231a74fb164ec9b1743.PNG

Share this post


Link to post
Share on other sites

At least adding fields to the user template is pretty uncomplicated and straightforward. I did this a lot in my forum implementation, the user template looks like this:

UserFields.thumb.jpg.5317615741c5e43bd48d2129e1466ade.jpg

 

Share this post


Link to post
Share on other sites
1 hour ago, joer80 said:

In this situation I want to allow users to attach Licenses to their user accounts.  Each will have 4 fields or so and they can have a number of them.  It would make sense to me to store them as children.

What about a repeater field on the User template? Or perhaps even a Profields Table field (if you have it).

Share this post


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

What about a repeater field on the User template? Or perhaps even a Profields Table field (if you have it).

That is probably what I will try next just so if a user is removed, I know the dependant pages will also be!  I just was not sure why the children method was not working and if I am not suppose to do it that way, if repeaters would be any safer. 

38 minutes ago, dragan said:

It's odd: If you try to add a child-page under Access > Users > usernameX > Tab "Children", you get these errors as posted above.

However, you can create child-pages via the page-tree without a problem!

user-child-pages.PNG.38d1ffd0bfab7231a74fb164ec9b1743.PNG

Good find!

If I do it via api, it would probably work also...

Share this post


Link to post
Share on other sites
12 minutes ago, adrian said:

The other option might be to make use of the alternate user template approach outlined here: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users

 

That is very interesting looking.  I will look into this...

I have a feeling the issue with adding children is because the user template is under the admin tree and it wants to use it like a process.  Maybe this would let me pull it out of the admin tree?  Not sure yet. 

Share this post


Link to post
Share on other sites

Hi,

The alternate user template approach @adrian mentioned is the way to go.

Actually, it really depends on what you want to do. For me, I added fields to the user template and it is good enough for me.

I put a page reference field in the user template and another field in some other template that need to store user id. Then connect the two page reference fields with the connect page fields module. It works great for me.

Gideon

Share this post


Link to post
Share on other sites
26 minutes ago, Gideon So said:

Hi,

The alternate user template approach @adrian mentioned is the way to go.

Actually, it really depends on what you want to do. For me, I added fields to the user template and it is good enough for me.

I put a page reference field in the user template and another field in some other template that need to store user id. Then connect the two page reference fields with the connect page fields module. It works great for me.

Gideon

does using the connect page fields module like that make it so deleting a user removes the other page also?

Share this post


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

does using the connect page fields module like that make it so deleting a user removes the other page also? 

Yes. You can try it out yourself.

Gideon

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...