Adding the Twig template and settings

Estimated reading: 2 minutes

Now that you’ve added both the Alias Module and the Settings Form, you’re ready to create the Twig template.

In the settings for your Alias Module you’ve added a line that may look like this:

'timber_template' => "{% include 'starter_user_info.twig' %}",

The value itself is a twig-template-string that – in turn – includes a file.  That file needs to be available somewhere in the twig-views directories.

This also means you need to make sure you give the file/slug a unique name. You will want to make sure that your plugin-file will get loaded and not some file that is accidentally named the same and is at a higher priority in the twig views-array.

In our plugin initialization we have added a callback to the filter that tells which directories are used by twig to look for templates.

Create a subdirectory in your plugin folder to match, and create the ‘starter_user_info.twig’ file.

    Loading the gist-code

Setting default values for __node__ settings

Because there are no __node__ variables for our settings form until we have actually opened and saved the form, we will need to set a default value for it.

Of course it makes sense to use the exact same value that is set as the default value for the field when we first see it. That way it will work as expected.

So, although we want to use the Settings Module-field called ‘starter_user’

{% set userid = __node__.starter_user %}

we need to provide a default value because on instance creation the value used will be null:

{% set userid = __node__.starter_user|default( 1 ) %}

This will use 1 as a default value, until the person editing the form-settings selects an actual user and saves the settings.

Share this Doc

Adding the Twig template and settings

Or copy link

CONTENTS