module_load_include loads file but also prints path to the file I am using the api function module_load_include to include some markup in a custom module. The markup gets included and I indeed see it on my page but I am getting a side effect that the path to the include file also prints on the page along with my markup. Here is what I have that's working but with the unwanted path being printed out.

function mymodule_page_build(&amp;$page) {

  if (!path_is_admin(current_path())) {
    $page['page_top']['mymodule'] = array(
      '#type' =&gt; 'markup',
      '#weight' =&gt; 25,
      '#markup' =&gt; check_plain(module_load_include('inc', 'mymodule', 'inc/markup')),
    );
  }

}


so the markup from my include file renders as HTML but I also see this on the page as well.

/sites/all/modules/custom/mymodule/inc/markup.inc


Just not sure what I am doing wrong, could not find any examples where this api function is used to include within the #markup context.
module_load_include returns the file path not the html. However the reason you are seeing the html is due to module_load_include also doing a require_once. An easy way to fix this would be something like the following

function mymodule_page_build(&amp;$page) {
  module_load_include('inc', 'mymodule', 'inc/markup');

  if (!path_is_admin(current_path())) {
    $page['page_top']['mymodule'] = array(
      '#type' =&gt; 'markup',
      '#weight' =&gt; 25,
      '#markup' =&gt; get_my_html(),
    );
  }
}


So now your #markup is a function call. Just make sure your html is wrapped in the function name you want and then use your function name in the #markup key.

Also, you function that contains the markup will be something like this.

function get_my_html() {
  $output = '';

  $output .= '&lt;div&gt;&lt;p&gt;Here is some of my HTML OR ALL of my HTML';

  return $output;
}


Hope this helps!