I have field "myfield" in a node. The field is created in the content, not by hook. I want to change the value of that field. I do not want to display the value from database, but my value let's say random number. I tried to do this with hook_node_view and with hook_entity_view but I cannot change it on the display. Here is my code:

function mymodule_node_view($node, $view_mode) {
  if ($node->type == 'my_node_type') {
    if ($node->nid == 46) {
      $node->myfield['und'][0]['value'] = 55;
//or I tried with $node->content and no success

What am I missing? Can you help me, please! Thanks you in advance!

1 Answer 1


You can use this line instead:

$node->content['myfield'][0]['#markup'] = '55';
  • Hi, I just tested and it is not working, too. The value with dump is changes but not on the display. Maybe I missed something but I do not know what. Thanks.
    – krasobko
    May 12, 2014 at 14:16
  • OK. It is working. I was testing the field that is editable (from editable fields module) but still I need also to change editable fields values.
    – krasobko
    May 12, 2014 at 14:27

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.