0

I would like to know how to test if a node is flagged.

In D7 : if ($ flag-> is_flagged ($ node-> nid)) But I discover D8 and I do not see how to do it with twig

thank you in advance

1 Answer 1

0

Write a function with hook preprocess_node in your custom module and set a custom variable isflagged ture or false then check this variable in your twig file node is flagged or not like

/**
 * Implements hook_preprocess_node().
 */
function yourModuleName_preprocess_node(&$variables) {
  $node = $variables['node']; // Just in case you need it

  if($variables['node']->getType() == "yourNodeType") {
    // your code 
    if ($flag->is_flagged ($node->id())){
      $variables['isFlagged'] = true;
    }else{
      $variables['isFlagged'] = false;
    }

  }
}

now in your twig

{% if  isFlagged %}
  //do some thing
{% endif %}

hope this helps you

1

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.