Jump to content
BitPoet

Template Parents

Recommended Posts

A feature request here in the forums prompted me to shape a piece of code I had been tinkering with into a usable module.

Template Parents

What it does:

The list of possible templates for new pages in ProcessWire is purely based on other templates in parent/child relationships managed in the involved templates' family settings.

This is most often okay, but sometimes you want to limit creation of pages with a certain templates to individual spots in the page tree, and there's no clear parent/child relationship to go with. The initially quick solution would be to duplicate parent templates for the different spots, but then any change on one of these templates has to be made to the others too, which gets tedious and error prone.

Template Parents adds an entry in the Setup menu where you can assign allowed parent pages to templates.

post-2900-0-07912600-1458482835_thumb.pn

These rules are enforced after the regular family settings have been executed, so it builds upon instead of replacing PW's built-in mechanism.

There's also an option in ProcessTemplateParents' to enable inheritance, then entries in the Template Parents assignment are inherited down the page tree and also grant template permissions to children, grandchildren and so on.

post-2900-0-97368900-1458482883_thumb.pn

The module can be downloaded from the GitHub repository. It has been tested with PW 2.7 and 3.0.

  • Like 15

Share this post


Link to post
Share on other sites

Great thing! And your reaction speed to forum requests is fascinating!

I guess it might not be too hard to integrate this into the template family tab. This way working with parent/child relationships would be easier - you do not have to go to 2 different screens for that. What do you think?

  • Like 2

Share this post


Link to post
Share on other sites

@Ivan: A good idea. In fact, the one I initially had in mind, but I somehow got it into my head to save the settings directly with the template configuration which I couldn't. Of course, one thing doesn't necessitate the other and I can both hook into ProcessTemplate and use my own database table.

So, version 0.0.6 is on GitHub and does allow that.

post-2900-0-91562000-1458494320_thumb.pn

  • Like 9

Share this post


Link to post
Share on other sites

BitPoet, many thanks for this module! :)

When attempting to go to the settings page for Template Parents Process in PW v2.7.2 I get an error:
"Undefined index: inheritSettings in ...\site\modules\TemplateParent\ProcessTemplateParents.module on line 232"

Also, do you think there's a way to have templates that have been given a parent page restriction with this module appear in the "Add New" menus?

Share this post


Link to post
Share on other sites

There was a silly mistake in the module config, but that should be fixed in the latest version on github.

Currently, the only way to get the template selectable once parent restrictions are in place is to add a valid parent to the settings. Can you describe a little more what kind of logic you have in mind?

Share this post


Link to post
Share on other sites

Currently, the only way to get the template selectable once parent restrictions are in place is to add a valid parent to the settings. Can you describe a little more what kind of logic you have in mind?

I'm thinking of the same "Add New" functionality you get when you use the core "Allowed template(s) for parents" + "Allowed template(s) for children" + "Show in the add-page shortcut menu" options. It lets you add a new page of a particular template in one step because PW "knows" where in the tree a page of that template is allowed to go. In theory this functionality could also apply to templates with a parent page restriction defined with your module, but I'm not sure how difficult it would be to extend the Add New functions to allow for this.

  • Like 1

Share this post


Link to post
Share on other sites

Loving this module - perfect for a site I'm currently developing.

Just noticed a bug: allowed parents selected from Setup > Templates > Edit Template are not saved successfully (no selection is saved). Allowed parents selected from Setup > Template Parents are saved okay.

Another thought: how about a sister module for Template Parents, "Page Child Templates"? So for any page you can define allowed templates that may be used for child pages.

Now I'm just being greedy :biggrin:

Share this post


Link to post
Share on other sites

I need to have a look what can go wrong with changes in template settings, it worked in my (limited) tests.

Not sure I want to go into the page/child templates direction though, as the data model is currently tailored to be template-centric. Making both ways efficient would add a whole layer of complexity (n:m relationship).

Share this post


Link to post
Share on other sites

Any ideas about how to get the one-step add Robin was asking about? Maybe add a setting in your module for name format.

...add a new page of a particular template in one step because PW "knows" where in the tree a page of that template is allowed to go

Greedy of me to ask but you seem to be a couple steps ahead of me on this.

Share this post


Link to post
Share on other sites

Any ideas about how to get the one-step add Robin was asking about?

@BitPoet: Incidentally, one reason I thought a sister "Page Child Templates" module would be useful is that it avoids any potential difficulties there might be in extending the "Add New" feature (which normally requires allowed templates to be configured for both parent and child templates, although it's not clear to me why the parent template restriction on children is logically necessary for this feature).

If it were possible to specify for a given page what template(s) may be used for child pages then the Page Add Bookmarks feature could be used in place of the original "Add New" feature. The Page Add Bookmarks feature just adds a page under a given parent in the tree, but if a "Page Child Templates" module has locked down allowed templates for that parent then you have a pretty foolproof substitute for "Add New" without having to add extra unnecessary templates for those parent pages.

Making both ways efficient would add a whole layer of complexity (n:m relationship).

My understanding of the relationships required is pretty limited, but looking at your code for the Template Parents module it looks like it could be adapted for a Page Child Templates module. The way I imagine it working is that for any page that has allowed templates for children configured, the module stores a row in a database table containing allowed template IDs for that page ID. Then when a new page is added, the filterAllowedParents function hooked to ProcessPageAdd::getAllowedTemplates filters the list of allowed templates according to any template IDs that are stored for the new page's parent page ID. But I might be overlooking some complexity here. I'll probably have a tinker with your Template Parents module to see if I can adapt it myself but I'm a bit of an amateur.

  • Like 1

Share this post


Link to post
Share on other sites

Another thought: how about a sister module for Template Parents, "Page Child Templates"? So for any page you can define allowed templates that may be used for child pages.

I have made a simple module for this: info here.

Share this post


Link to post
Share on other sites

Just noticed a bug: allowed parents selected from Setup > Templates > Edit Template are not saved successfully (no selection is saved). Allowed parents selected from Setup > Template Parents are saved okay.

Hi @BitPoet,

I just created a GitHub pull request with a fix for this. Cheers. :)

  • Like 1

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.

  • Similar Content

    • By eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild. 
      EDIT: You can now install it directly from the Modules directory: http://modules.processwire.com/modules/inputfield-float-range/
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Optional step value (Read more) Optional manual override of the selected value (will still adhere to the rules above) Configurable rounding of manually entered values (floor, round, ceil, disable) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant  
      Changelog
      005 (current version)
      - Fix bug where the Inputfield would not work properly within repeaters / repeater matrices
      004
      - Make rounding of manually entered values configurable (floor, round, ceil or disable)
      - Fix small JS bug when the value-display field was not displayed
      - Update README
      003
      - Code cleanup, add some ModuleInfo data & LICENSE
      - Submit to PW Modules directory (http://modules.processwire.com/modules/inputfield-float-range/)
      002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional
      001
      - Initial release
       
      Thanks!
       
       
    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-10-18
      2019-08-08
      2019-06-15
      2019-06-02
      2019-05-25
      If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
×
×
  • Create New...