Jump to content

Automatic template file generator


Recommended Posts


I was reading a very interesting post in this forum (https://processwire.com/talk/topic/7166-wp-tavern-article-and-processwire-themes/page-4), about PW and its popularity compared to other cms like Wordpress.

The key point that has been discussing is: how can PW be more attractive to non developers (ie designers)?

(ok here another question arises "Do we want that PW reach an audience bigger that developers only?" but this is another topic...)

Wordpress for example has a theming system that certainly is very attractive and quite easy to use, and I noticed someone in the community is already working on a module that could do some steps in that direction.

That could be great but there's another thing that in my opinion could help very much: an automatic template file generator.

Let me explain...

I think that one of the things that scares a person which is not a developer the first time he uses PW, is the fact that after creating some fields and a template that contains these fields from the administration panel, he has to create a new empty file named as the template and put it inside the templates folder.

Obviously from a developer point of view this is not a big problem, I go searching the docs and try to find what to put in this file, but from the point of view of a person that has no the developer mental scheme that thing could be scary at the beginning, and I imagine that if this person is trying out a lot of cms to find out which is better for him, he could easily think "ah dawn this is too complicated for me!".

Ok, so what if I can, after creating a template, press a button and let the system create the template files for me? This could be great!

I can now go to PW tree page, add a page with the template I created before and when I navigate the site I have already a page that is working, and it also outputs the fields that I filled!

Then, I go editing the template file that has been created automatically and change the html as I prefer, but I don't have to bother about php code at all...

The next step is thinking about a small wizard that create the file when I press the generator button: for example I have to choose if I am creating a simple detail template or a list template. In case of the list maybe we need the user to enter some filter parameters to generate the array list (template type, parent, etc.) and so on...

So, this is not a trivial task but maybe not even impossible.

In the future you can also think about a way to make this module useful even for developers, for example creating some template for outputting the html of the template files.... But maybe I am going too far :D

So basically I think it could be very interesting to create a module that adds this functionality to PW...

What do you think?

  • Like 1
Link to comment
Share on other sites

I think the idea is possible but it would have to make certain assumptions about what people want to do (favourite would be to provide the most common output).

For example with an images field storing multiple images I might suggest they get outputted as thumbnails in a UL element and have thumbnails link to larger versions.

Anything like this would also be best if it spat out comments in the template as to how to change things or rather link to relevant parts of the documentation and API.

It's not impossible to do, but at some point you're just going to be recreating what's already in docs like the Planets tutorial, but possibly without people bothering to read and learn what's going on. I guess what I mean is there's always a trade-off when lowering the barrier to entry, so perhaps if the auto-generated templates were very well commented that would make up for it.

  • Like 2
Link to comment
Share on other sites

Just for the record (I can see that other arguments have already kicked in), I'd like to point out that this would also require ProcessWire (and thus your Apache user) to be able to create and modify files within /site/templates/.

This, in my humble opinion, is not a good idea; even with proper safeguards in place, web-writable executable files open all sorts of possibilities for abuse. You don't want to go that route unless you absolutely need to -- and I can't imagine any situation where I'd actually want to do that.

  • Like 3
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

  • Create New...