This project is not covered by Drupal’s security advisory policy.
This module and its sub-modules are fulfilling the need to have a template selector for content types using standard Drupal entities.
The Problem
Drupal is a great content management framework for developers but it lacks an essential part that other frameworks provide which make the mission of the Site builders and content admins easier that is related to select a template for each content type out of the box.
The solution
This module comes to fulfill the need to have a template selector from the node edit form using a term reference field that allows you to define the template that you can use for this specific content.
How it works
This module is intended for developers and themers which allow them to create templates with custom template names that can be used by the content admins/authorized users.
This module contains the following modules:
- the API module; which does nothing by itself other than providing common functions to be used by developer and themers to create custom modules and take advantage of this module.
- Node Template Selector; which allows you to have a field in your content type that allows you to select the template to be used with that content
- Website Sections Template Selector module; which will help using the template selector for the taxonomy term and to theme the content inside that term page. This module uses a new Website Section vocabulary to use the template selector with terms also introduces a new field "Nodes Term Template" in the term add/edit form that allows using specific templates for the nodes within the term. A good usage example is to have news (as term) page and the news nodes inside of it
- Template Selector Admin Module which is accessible on admin/config/user-interface/ts/fields which allows to injecting the template control fields "Entity Template" and "Nodes Term Template" along with linking the content to the website section terms using "term reference field".
- I made a dependency on the node order module in order to allow organizing the nodes inside the term page.
Node Template Selector module creates a taxonomy vocabulary named "Entity Template" which will be used to name the templates that you want. Also, it creates a field named "Node Template".
By using taxonomy terms as template names we are taking full advantage of Drupal field API that allows the developer to define sub-features of the template by editing the fields in the Entity Template vocabulary.
Install the modules
Install the Template Selector and the Node Template Selector modules as usual following the steps described here
Configure the Module
Add the Entity Template field to your content
navigate to Structure > Content Types, and select [manage fields] of the content type that you want to it to use the Node Template Selector.
From "Add existing field" section, select "Term reference: field_node_template (Node Template)" and press save.
Add New Template Name
Basically, you need to add the template name as a term to Entity Template vocabulary. Do the following:
Navigate to Structure > Taxonomy > Entity Template and press on "Add Terms"
Add the name of your template. It worth mentioning that you can use spaces, upper-case letters and numbers in your template name, Only the special characters are not allowed. Press "Save"
Add your template file and its related CSS and Js files
The main intention of this module is to help to create complex templates as modules on top of this module but in case you need a quick solution you can do the following:
You can use the "Template" directory at the root of this module to put your template files, also you can attach your CSS and JS as the following by putting them in the CSS and JS directories at the root of this module.
Naming Template file:
I tried to make the naming of the templates similar to the default templates naming, and through this example, you should be able to do it:
- Let assume you created a new term in the Entity Template vocabulary as "Fullwidth Image"
- This module replaces the spaces with "-" and make characters small
- All templates for nodes should start with "node--"
According to this, your template name will be "node--fullwidth-image.tpl.php"
Road Map
This road map of this project will go in 2 directions:
- developing templates modules that add complex features to the templates through using content fields to specify the properties of the template
- Using taxonomy terms templates that can control its template and how the content related to it appears inside of it. As an example is to have the term "news" in a vocabulary called "tags" to contain all articles marked as "news" and control how they should appear with complex options. We call this features a "Container page"
Project information
- Project categories: Content editing experience, Developer tools, Content display
- Created by hodba on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
