Skip directly to content

Template Picker Now Supports Entities

January 25, 2014

Several months back, I released a module to drupal.org, called Template Picker. The idea was that it was too difficult to set up a workflow where content creators could pick how they want their content to be displayed. It either required heavy site building using tools like Panelizer (outside version control), or one-off custom development.

The way Template Picker works, you drop node templates into your theme for each way you'd like to display your content, and, as long as the file name matches the naming convention, it will be available as an option on the corresponding node-edit page. If that's too much Drupal lingo for you, you can see a video demo here.

But what I really wanted was to think outside the node and see if we could allow template picking for all sorts of entities. This way, a user could choose a style for their user profile, or a content admin could assign taxonomy term listings to predefined displays. It took some digging into the entity API, but I finally got it coded up and released over the Christmas holiday. I also depricated the old project on Drupal.org to fix a renaming issue (kind of a pain, but that's the price of learning).

If you think something like this could be useful for your next project, you can check it out on Drupal.org.

Comments

Nice article and nice module Bryan!
A possible application of your module came up today. We have a client that uses some blank basic pages (node/xxx pages) just so that they have an anchor/placeholder/canvas to put certain blocks on that are configured to displayed on those node/xxx pages only, using the block visibility settings that require such a node specification as an anchor/placeholder/canvas.
This works fine but has the drawback that the node title and the View/Edit/... etc tabs/links still display for the otherwise empty basic page -- a fly in the ointment.

The View/Edit/etc. tabs are rendered, I believe, not by the node.tpl.php template but by the page.tpl.php template. So, if your module could also deal with page.tpl.php variants, then the client could realise their use-case with your module by selecting a page--blank.tpl.php (or similar) template.

That would be much more elegant for a content editor or site builder than asking a Drupal developer to suppress the tabs using CSS using a selector that involves a hard-coded node id.

Your thoughts?

Rik

You're right, a CSS selector with a hard-coded node id is would make managing it difficult. If you wanted to go the CSS route, I'd try to find a way to print a "blank-node" class that you can base css rules off of. You could do this with custom development via adding a select list to your content type, and using it's value to trigger preprocessing in template.php. Also, if you're using Context, you can set body classes per context.

Of course, a "Page Template Picker" type of module would certainly do the trick. I'm still mulling over how something like that would integrate well with Template picker. In the mean time, you may be interested in this Sandbox project I found that was working on similar functionality, or this Drupal 6 module that does something similar.

Post new comment