0

In my content type I have an entity reference field. With this field editors can create internal links effordlessly with the autocomplete function.

What I want to achieve is that editors can now customize the text to output the referenced node. E.g. The editor creates a reference to a node and in a different field creates the "title" of the reference, she has just created. Thus references can have custom display titles.

I have tried the token formatters module (http://drupal.org/project/token_formatters) but to no avail.

In my particular case I have a field reference_text and have set the format of my entity reference field to "Tokenized text". In the "Text to output" field I have tried the following: 1) [node:reference_text] 2) [current-page:reference_text]

With 1) an empty field is displayed. With 2) I get an error message: Text output uses the following invalid tokes: [current-page:reference_text]

Not sure what else to try. Any help would be greatly appreciated. Big thanks in advance.

1 Answer 1

1

Two different options here (there are probably more!):

  1. Use the linkit module in combination with wysiwyg and, say, the tinyMCE editor. This allows users to insert node reference links into wysiwyg text areas.
  2. a. Create a textfield for the link text in addition to the entity reference field.

    b. In the template file for the content type (node--CONTENT_TYPE.tpl.php), output the links manually, something like:

    $path = 'node/' . $node->YOUR_ENTITY_REF_FIELD['und'][0]['target_id'];

    $link_text = $node->YOUR_LINK_TEXT_FIELD['und'][0]['value'];
    
    print l($link_text, $path);
    
2
  • Thanks for the quick response. I wanted to stay away from creating a node template as I am not particularly good at PHP but will try a solution. I had hoped that I could do this with tokens, though. The linkit module is unfortunately tied to an editor, which I do not want my clients' to use. I will let you know about the template approach.
    – criscom
    Commented Feb 20, 2014 at 20:45
  • I solved it with the linkit module. I created a text field and chose the linkit option in the configuration of the field. Thanks.
    – criscom
    Commented Feb 21, 2014 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.