Include php file inside a block

Permalink
I have a block that has a hero image that is a full screen background image that I need to attach a css style to it that adds the image. I then need to pull in my nav via an include. So I need my block to be dynamic where I can add text and add a style to the wrapper of my block.

I now get an include file not found error as it's looking in my block directory instead of the theme folder path.

How can I dynamically add a style for my block whilst including a file?

<div class="sub-b-hero my-background-image-style">
    <?php $this->inc('partials/global/_header-main.php'); ?>
    <div class="container">
      <div class="row">
        <div class="col col-sm-12 col-md-9 col-lg-8">
          <section class="hero-main-c">
            <header>
              <h1>this is dynamic text</h1>
              <p class="sau-t-white pt-2">this is dynamic text</p>
            </header>
          </section>
        </div>
      </div>
    </div>
  </div>

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi ServersAustralia,

In your block view.php, $this is a Concrete\Core\Block\View\BlockView object, which is why it is looking in the block directory for the file.

You can try this:
$v = View::getInstance();
// $v is a PageView object
// Concrete\Core\Page\View\PageView
// using inc() on the PageView object looks in the the current theme folder
$v->inc('partials/global/_header-main.php');
ServersAustralia replied on at Permalink Reply
Great...Thanks!
chawilaclef replied on at Permalink Reply
chawilaclef
This will work apparently but will return false, so for me the page holding the block become not publishabled.

if ($v->inc('partials/global/_header-main.php')) {
echo "ok";
} else {
echo "not ok";
}
will return not ok, even if the file is well called and emebed.