Version:
Cohesiondx.com

Are you looking for the latest documentation?

Documentation for Acquia Cohesion V6.0 onwards has moved to https://cohesiondocs.acquia.com

    Connecting your templates to fields

    For your templates to display content they need to be linked to fields.

    For the purpose of an example, the following steps are for connecting fields in a Content type to fields in a template as this is the most common use case. The same process applies for all other content entity types like Taxonomy vocabularies. 

    Linking fields to template elements

    When linking your template to a field in your Content type, you link the field within your DX8 layout element to the field in your Content type. The diagram below shows an example of linking an Image field in a Content type to an Image field within the Image element on a template. The result is that the image uploaded to the Content type will render where the Image element is placed on the Content template.
     

    mapping-data-to-field.png

    To link a field in a Content type to a field in your Content template you have two options:

    Option 1 - Use the field element

    You can render the content of a field from your Content type within your template using the Field element. When you use this option, the template will render the processed output of the field. The main use for this is when you want to render the complete field. For example, use the Field element to render the Body field from your content type.

    You cannot add Styles or other markup to the Drupal field element.

    To use the Field element:

    1. Navigate to DX8 > Templates > Content templates > Content type
    2. Select a template and click Edit
    3. Drag a Field element onto the Layout canvas
    4. Double click on the Field element to edit its settings
    5. In the drop-down, select a field from your Content type to render. For example, Body
    6. Click Apply
    7. Click Save and continue.

    Option 2 - Use tokens in your template

    You can use tokens to render dynamic data from your Content types into fields in your Content templates. Tokens are specially formatted blocks of text that serve as placeholders for a dynamically generated value. They consist of a Type and a Value and are always contained within square brackets like this [node:title]. In this example, node: is the type and title is the value. You could use this example to render the node title into the Heading text field in a Heading element on your template.

    You'll nearly always use tokens to link fields in your entities to fields in your elements because you can then apply styles to them.

    The following example shows how to use a token to render the Title field in a Content type into the Heading text field of the Heading element. The same process will apply for other tokens and fields.

    Step 1 - Add and edit a heading element

    1. Navigate to DX8 > Templates > Content templates > Content type
    2. Select a template and click Edit
    3. Add a Heading element to your layout canvas
    4. Double click the Heading element to edit its settings.

    Step 2 - Open the token browser

    1. Within the Heading element, click on the Open token browser button
    2. The token browser will open in a modal.

    Step 3 - Locate the token

    1. Use the token browser to find the field you want to render in your template. For this example, open Nodes and find Title. For more information see Using the token browser

    Step 4 - Toggle variable mode and insert token

    Toggling variable mode converts all the fields in your element to text input fields so that you can insert tokens within them.

    To insert a token:

    1. Within the Heading element, click on the Toggle variable mode button
    2. The fields will all turn to yellow text input fields
    3. Click into the field you want to insert a token. For this example, click into the Heading text field
    4. Now, in the token browser click [node:title] next to Title
    5. The token will be inserted into the heading text field within the element
    6. Click on the Toggle variable mode button
    7. All the fields will turn back to their original state except for those containing tokens
    8. Click Apply
    9. Click Save and continue
    10. The Title field from your Content type will now render into the Heading text field in your Heading element within your template.

    To toggle variable quickly, Alt Click on the Sidebar editor outside of a field. 

    Deleting tokens from fields in Elements

    To delete a token from a field:

    1. Within the Heading element, click on the Toggle variable mode button
    2. Select and delete the token text from the field
    3. Click on the Toggle variable mode button
    4. The field will return to its original state without a token.
    5. Click Apply.

    DX8 knowledge base icon

    Frequently asked questions

    Get instant answers to common questions. Available online 24/7.

    Find answers

    Raise a ticket icon

    Raise a support ticket

    To raise a ticket, sign into Acquia Cloud and select Help in the top menu.

    Raise support ticket

    Acquia

    Copyright © 2020 Acquia, Inc. All Rights Reserved. Drupal is a registered trademark of Dries Buytaert.