Jump to content

Show field only $home or $home->child page


Thomas F.
 Share

Recommended Posts

Hello,

I'm very new in processwire development and I have a question and I hope somebody can help me.

I developing a site with a logo in the middle auf the top navbar. On the left and the right site from the logo two navigation links (or maybe more).
I insert a select-field in the template with two entries: LeftFromLogo and RightFromLogo
Now it's possible for the user to decide on which site the navigation link appears.

So now my problem. The select-field should only appear when user create a page under the $home ($home->children).
I used: "Show this field only if" with different entries but with no success.

OK i can solve this with different templates, but this is also for me to learn.

Thank you for your support
Thomas

 

Link to comment
Share on other sites

Hi, and welcome to the forums!

I recommend that you use different templates for the home page and child pages. This should make doing what you need in the back end (editing) pages straightforward

Then for the template files, there are various approaches you could use. Probably the easiest would be the one described under "Direct Output with Includes" at https://processwire.com/docs/tutorials/how-to-structure-your-template-files/. For example, the includes for both template files might be head, body and footer sections, but a menu section could be different in each.

Let us know if you need further help!

  • Like 1
Link to comment
Share on other sites

13 hours ago, Thomas F. said:

I used: "Show this field only if" with different entries but with no success.

The core show-if can only work when the test relates to values that are contained in inputfields in the Page Edit form, (e.g. "some_field=foo"). Technically there is a field in Page Edit that relates to the parent - the "Parent" (parent_id) field on the Settings tab. But that inputfield is set to AJAX-load so the value isn't available to the inputfield dependencies JS.

But you can use the Custom Inputfield Dependencies module to create show-if conditions that are evaluated by PHP rather than JS: https://processwire.com/modules/custom-inputfield-dependencies/

You would create a show-if condition like this:

image.png.fcc4498787ade9fcff6739e4d543b730.png

  • Like 3
Link to comment
Share on other sites

16 hours ago, Robin S said:

The core show-if can only work when the test relates to values that are contained in inputfields in the Page Edit form, (e.g. "some_field=foo").

It also has issues like fields not having edit rights make conditions not being evaluated properly. Also, Presentation settings like "Open + Locked (not editable)" and others make it fail to work. The way it is implemented in the core is half baked, has not been taken care of for years and based on the probably wrong design decision that it can be done with JavaScript only.

@Robin SYour module is a lifesaver indeed. Thanks a million!

  • Like 2
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...