title: What is the correct context id of Moodle block
body: <p>What is the correct <code>context id</code> of <strong>Moodle block,</strong> <code>block_html</code>. </p>
  
  <p><strong>case1</strong></p>
  
  <p>In <code>block_html.php</code> file </p>
  
  <p><code>$this-&gt;context-&gt;id</code> inside <code>get_content</code> function gives <strong>122</strong></p>
  
  <p><strong>case2</strong></p>
  
  <p>I create a new page named <code>view.php</code>. Here I try</p>
  
  <pre><code>$instance = $DB-&gt;get_record('block_instances', array('id' =&gt; 57));
  $blockname = 'html';
  $block = block_instance($blockname, $instance);
  echo $block-&gt;context-&gt;id;
  </code></pre>
  
  <p>and this gives <strong>98</strong>.</p>
  
  <p><strong>case3</strong></p>
  
  <pre><code>$context = context_block::instance($cmid);
  
  echo $context-&gt;id
  </code></pre>
  
  <p>gives <strong>7</strong></p>
  
  <p>What should I use as <code>context id</code> of <code>block_html</code>. I need the exact <code>context id</code>.</p>
  
  <p>Note: For all blocks I am getting the issue described above. What is the wrong I used?</p>