It would be great to be able to specify a default template per node.

Defaults could be set on the content type admin page, similar to how better formats introduces an "input format settings" tab. A drop down selecting the default template would be swell.

Configuration could be extended to allowable templates. Checkboxes could provide the option to include/exclude templates per node type.

In our use case, we are trying to provide by default a 2-column layout on pages. Some pages use an optional single column template. We don't want to offer templates at all on news pages, especially 2-column ones.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guybedford’s picture

Thanks for sharing your use case. In terms of how it fits in with this module, it is actually a very different functionality in what this offers.

If I understand right, you are suggesting that for each content type you would like a default template to automatically populate in the body field. This can be done quite simply with the following module hook:

function mymodule_nodeapi(&$node, $op){
  switch($op){
    case 'prepare':
      if($node->type == 'page' && $node->body == ''){
        $node->body = '<p>sample html</p>';
        //OR
        $template = wysiwyg_template_load_template(1);
        $node->body = $template['body'];
      }
      break;
  }
}

Then in terms of permission-based templates for content types or roles, this is certainly a feature that can be offered given enough support.

Hope that helps.

Andrew_Mallis’s picture

Thanks for the code (and your work on the module). Great stuff! I will definitely employ that.

The kind of templates offered up for static content, or blocks differ from those on blog posts, for example. Blog posts might not even deserve a template.

This is icing, though, and food for thought.

guybedford’s picture

Actually yeah I get you... it is a very useful feature to set templates per node, and then optionally have a default template auto-populate when creating content.

Will see if I can add this in over the next couple of weeks.

chichilatte’s picture

Would love to see this as part of the module, yup. Thanks for your hard work!

guybedford’s picture

Any patches for this feature would be more than welcome.

jurgenhaas’s picture

Version: 7.x-2.4 » 7.x-2.x-dev
Assigned: Unassigned » jurgenhaas
Issue summary: View changes
Status: Active » Needs review
FileSize
21.79 KB

No I got around to implement this and attached is a patch which does the following:

  1. Add a new database table to store the relationship between wysiwyg templates and content types
  2. Provide an update script to create the new table
  3. Hook into the node type form to add a select field, where a template can be selected as default for this node type and store the value into the new table
  4. Hook into the node form and insert the content of the default template if there was any and if it's a new node only

The attached patch is a little bit larger because my IDE has also reformatted the code of the whole module so that it is now compliant with the Drupal coding standards.

guybedford’s picture

Thanks Jurgen - this looks great.

I'm seeing everything work, except when inserting a template, it isn't selecting the default one. I'm using CK Editor 3.5.2 - perhaps I need to update.

I like the way this is structured a lot. It could also be useful to allow filtering the available templates by content type. So articles only see some templates etc. But that's just a suggestion.

Please feel free to commit these changes to the dev branch. I trust your judgement at this point, then just let me know when you think you are nearing a release point and I will do a review for release.

jurgenhaas’s picture

Thanks Guy for your quick response. Having two issues:

1) I can't push the code back to the dev release, I get a 403-error. Maybe I haven't got permission yet?

2) You're saying "it isn't selecting the default" one and I'm a bit confused by that. If a default template is defined for a content type, then that template will already be there if you open the node edit form, you don't have to select that template from the list anymore. And that works completely independant from the used editor, because the template is inserted into the body field before the form gets delivered to the browser.

So, that sounds as if something is not correct in your installation yet. Maybe we postpone that until we have the code in the repository.

guybedford’s picture

1) All the maintainer permissions are definitely enabled. You have every permission except Administer Maintainers. Can you try again? I'm not sure what else I can do this side.

2) Oh right - sorry I didn't understand that this was the behaviour. That sounds really great! We should document this as well when it is released.

jurgenhaas’s picture

The push now worked OK, for some reason I had to clone my working copy from source again, something was wrong with the first one.

Now let's test and finalize this feature with defaults per content type and then I'd love to continue with what you mentioned as well: optionally assign each template to one or many content types, so that these templates only show up there.

guybedford’s picture

Sure, let me know if you're thinking of working on the filters before or after the release. Either works for me. If you do want to release it now first, I'm more than happy with that - will just do a final code review.

jurgenhaas’s picture

For some reason, my last comment didn't get posted. I have included the filters so that templates can be limited to certain content types and if everything got reviewed successfully, we are ready for a new release.

guybedford’s picture

Amazing, this is all working great, and the updates are running smoothly for me.

Happy to release when you are.

jurgenhaas’s picture

Status: Needs review » Closed (fixed)

That's great, thanks Guy for the review. I'm going to release all the changes just now.