Feeds

Author

Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough
Feb 09 2021
Feb 09

To enable visitors to the site to navigate more effectively via individual assistants that inform and direct them to the relevant topics depending on the context - that's what we wanted to realize for one of our projects. The goal behind this is to give end users the information they need quickly and easily at the time they need it.

In the World Wide Web such assistants can be found more and more. However, for our Drupal project we did not find the right thing for our needs - neither an existing Drupal module nor a service provider offering such a solution. So it was clear: A new module was needed. And this module should be available as a contribution for the whole Drupal community. Voilá, a few days later we developed the Site Assistant module.

View of a site assistant in action.View of a site assistant in action.

Requirements for the assistant

The overall requirement for the assistant is: It must be easy to use and well adaptable. Editorial teams should be able to create their own assistants with customized content for different areas. In addition, we defined the following requirements for the new module:

  • The content is created and maintained editorially.
  • There can be multiple assistants with different content.
  • The assistants are displayed depending on conditions (condition plugins).
  • The design of the assistants is customizable.
  • The assistants are sticky and usable in the different viewports.
  • Editors create assistants themselves, without a site builder and without the need for deployment.

This is inside the new Drupal module

From a technical perspective, the condition handling for the context-dependent display of the assistant is certainly the most exciting part. The Site Assistant module uses the existing condition plugin system and builds on it.

The display of our assistants is controlled by the conditions. A big advantage of the condition plugin system is that the Drupal community continuously provides new condition plugins and expands the selection more and more. For example, there are already condition plugins for the Drupal Commerce module for online stores. So if your Drupal site already has a store that uses this module and its condition plugin(s), you only need to activate the Site Assistant module and you can directly use the existing conditions from the store for the assistant as well.

The Site Assistant module itself is divided into three sets: the assistants, the assistant list items, and the assistant library content.

  • The assistants themselves are composed of a content field and a display options field. In the content field, the content to be displayed is placed and arranged using multiple list entries as needed. The display field is used to configure the conditions (condition plugins) on the basis of which the assistant is to be displayed.
  • The assistant list items are the contents that are displayed in the assistant. The module already brings a set of predefined list item types: headline, link, link list, subpage, library content, free text (wysiwyg). Site builders can create their own list item types, giving editors more choices in content design.
  • Assistant library items are content stored separately for reuse, and can be used in different assistants. An assistant library item consists of any number of list items. For example, for recurring contact opportunities, an assistant library item can be created with the heading "Contact" and a wysiwyg field with address, phone number and email, which is then used in different assistants.

The design of the assistant can be customized at different levels. Since each item in the assistant is a separate entity, they can be customized and formatted as usual via Drupal templates. The general design of the assistant can be customized via CSS.

Entry form for the fields of a site assistantEntry form for the fields of a site assistant.

And what's more?

With our new module there is now also the possibility to easily and quickly introduce context-dependent assistants in Drupal in order to better support the end user. The Site Assistant module brings a good base, but of course there is still a lot of potential for extensions and customizations. With a little development effort, you can create your own custom conditions (a tutorial can be found on Drupal.org) and customize the functionality exactly to your needs.

We would like to see more assistant list item types shared by and for the Drupal community so that the possibilities with the assistant grow. For example, I can very well imagine chat bots (possibly directly via service providers) being integrated into an assistant.

Jul 04 2013
Jul 04

This post adds to the successful and popular "Theming in Drupal 8 with Twig?" (Part 1, Part 2) series from Steffen. It deals with converting Drupal phptemplate themes to use the new Twig template engine, like we recently did with our Busy theme. This is all for Drupal 8, so this might not be helpful to you just yet, but if you wanna get a headstart on converting your phptemplate theme to Twig, nothing's holding you back from starting right now! If you don't know how to get your Drupal 7 theme to Drupal 8, there's an older write-up on how to convert a Drupal 7 theme to Drupal 8 in our blog (keep in mind that things in Drupal 8 change rapidly so some of that text might already be outdated).

First of all, Drupal 8 has Twig as its default template engine. That means if you don't write any other setting into the THEME_NAME.info.yml, Drupal will use Twig as its template engine. So, if the current theme is based on phptemplate, you must delete the line "engine: phptemplate" from your THEME_NAME.info.yml. In the following example it's line #5.   

  1. name: Busy

  2. type: theme

  3. description: 'The ultimate Drupal business theme.'

  4. core: 8.x

  5. engine: phptemplate

After that you can start with the "real" rebuilding. Make sure you know the basic syntax and features of Twig.

Copy the template file and rename it from TEMPLATE_NAME.tpl.php to TEMPLATE_NAME.html.twig. Then you have to look at each line and replace PHP commands with Twig commands. The following example shows you such a conversion of a template file:

Similar conversions have to be applied to arrays and loops.

  1.   {% set users = ['Paul', 'Guenther', 'Max'] %}
  2.   {% for user in users %}
  3.     {{ user }}  

  1. $users = array('Paul', 'Guenther', 'Max');
  2. foreach ($users as $user) {

  3.   echo $user;

  4. }

If you like to save some time, there is a nice Drupal 7 module called Twigify (sandbox-project). It tries to convert your theme automatically from a phptemplate theme to a new Drupal 8 Twig based theme. But keep in mind: complex code still needs to be edited manually.

So, don't be afraid of converting your themes to use the Twig template engine, it isn't that hard.

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web