Can I use the path() function in twig to create a link to a non-node entity add form. Taking the group module as an example, if I want to create a link to the 'group/add' page in twig can I use something like:

{{ path('entity.group.add') }}

I know that the above does not work, neither does

{{ path('group.add') }}

Not sure if there is a way to do this with the various twig functions that create links.


According to According to Functions - In Twig Templates just Try

{{ path('node.add', {'node_type' : 'yourcontenttypename'}) }}

as the example for article content type

{{ path('node.add', {'node_type' : 'article'}) }}

Update Try

{{ path('entity.group.add_form', {'group_type' : 'yourgrouptype' }) }}
  • Thank you for the response. I tried something similar for 'groups' and it did not work. So whilst that works for entities of type 'node' - I do not think it works for other/custom entities. I have updated my question to specify that I am asking about non-node entities. – bletch Mar 27 '17 at 13:38
  • Thanks again. {{ path('entity.group_type.edit_form', {'group_type' : 'yourgruoptype' }) }} results in '/admin/group/types/manage/organisation'. – bletch Mar 27 '17 at 16:13
  • 1
    But you did give me an idea, and it is working with {{ path('entity.group.add_form', {'group_type' : 'yourgrouptype' }) }} – bletch Mar 27 '17 at 16:15
  • Will mark as accepted answer since you got me most of the way there. Will you update with the one from above so if anyone else is looking for this they see answer in your comment? Thanks again! – bletch Mar 27 '17 at 16:16
  • @bletch you're welcome I add it to answer for future guys visits this question. – Yusef Mar 27 '17 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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