contentfulcontentful-managementcontentful-api

How to place dynamic value in contentful?


I am using contentful. In one of the content model, I want to display dynamic value based on the option selected.

e.g. In contentful, I am having message as: Congratulations, your <USER_TYPE> account has created successfully.

I have options as admin/moderator/user then if

  1. I select admin, message should get display as: Congratulations, your admin account has created successfully.
  2. I select moderator, message should get displayed as: Congratulations, your moderator account has created successfully.

How can I replace <USER_TYPE> with the selected values? Please guide.


Solution

  • I got the answer.

    In contentful, put the variable as {{ variable_name }} and in the code replace that variable_name with dynamic value as:

    import Mustache from 'mustache';
    Mustache.render(value, {variable_name: variable_value});
    

    I am using vueJs, so this implementation refers javascript.