When does the application directory get ignored

How do I access an element in application/elements from both a single page and a block?

Sometimes I find that the application directories sub-directories get ignored. For instance, when adding an element to the application/elements directory I expect the .php file to get picked up when calling the following from a single page,

$view->element('foobar', array('user_id' => $i));

but instead I get the error,

... concrete5-8.4.3/concrete/elements/foobar.php): failed to open stream: No such file or directory

It seems to completely ignore the file I've placed in application/elements.

I have only been successful accessing an element in application/themes/<theme>/elements using,
$view->inc('elements/foobar.php', array('user_id' => $i));

But now I want to use that same element in a custom block.

Thanks for your assistance,

View Replies: View Best Answer
mnakalay replied on at Permalink Reply
I totally agree with you and would also expect elements to work as you describe.

Looking through the code it seems it is intended to do as you say.

The only reason I see it wouldn't pick up your application element is if you had another element with the same name in your theme's folder.

Sorry I just read your post more carefully and my explanation doesn't hold water.
mnakalay replied on at Permalink Reply
I just tried it and it works as expected. The error must be somewhere else. Can you share your single page's view and controller code?
bonovasitch replied on at Permalink Reply
I wasn't using a controller. If I add a controller and add the $view->inc to it's view function then the page will render (no error) but my element doesn't appear to render.

## Edit ##
Previously, I had my single page at the root of application/single_pages. If I change the structure to application/single_pages/<pagename>/view.php then magically the element gets picked up as intended. Could this be a bug?
## /Edit ##

Can you help me with accessing application/elements from a block's controller? $view isn't available, so if I try,
use Concrete\Core\Block\View\BlockView;
class Controller extends BlockController
    public function view()
      $view = new BlockView($this->getBlockObject());
      $view->element('listings', array('property_id' => $property_id));

I get, "Call to undefined method Concrete\Core\Block\View\BlockView::element()"
mnakalay replied on at Permalink Best Answer Reply
You should really be including your element in your block's view.php file, not in the controller.

The element() function doesn't exist in the BlockView class, it exists in the Concrete\Core\View\View class. It is a static function so, in your block's view.php you should be able to use it like this
\Concrete\Core\View\View::element('listings', array('property_id' => $property_id));
bonovasitch replied on at Permalink Reply
Great! Thank you for your help.