Dry-web-roda and dry-view - I'm missing something


#1

Hi, I’m having a play with dry-web-roda and dry-view and I’m clearly missing how things work.

I’m trying to use the forme and assets plugins for Roda…but Roda plugins don’t automatically show up in the dry-view “context”. I have no idea what I’m supposed to do to connect things up.

I’m sure there is some simple “a-ha!” moment waiting for me. I’ve dug through the code and I’ve even managed to find a (not very appealing) way of getting the roda instance into my views (by passing it in as a local variable) so that I can call roda.form. But even that isn’t enough to allow me call assets or roda.assets from the application layout.

I’ve searched for example applications that might help. But most seem incomplete, out-of-date, or simply too simplistic to show things like I’m trying to do.

I’m struggling with dry-container, I think. I don’t really get what problem it solves - it isn’t one that I seem to have encountered. I suspect I somehow need to connect roda, the container and the view context - but I have no clue how.

If anyone could spare the time to explain what I’m missing here, it would be greatly appreciated.

Thanks in advance.


#2

Hi @brushbox, while in dry-web-roda projects we do use Roda for routing, it’s not intended that roda be mixed with dry-view when it comes to view handling. It’s true that there are a bunch of Roda plugins out there to help with view rendering, but they operate in a very different style to dry-view. The best way to think about things would be to think about dry-view as a standalone view rendering system, which you can easily call into from within Roda routes.

So if you wanted to make form helpers or assets available to all your views, the best way would be to make them available via the context object. Any method on this object is made available on the template scope.

While it might be technically possible to somehow pass the Roda instance into the context object, I bet this would likely just make for some awkward times. So it’d be better to make your assets, forms, etc. available in some standalone way. We do this in our own apps by e.g. having an “assets” object resolvable via the container, which can then be auto-injected into the class used for the context object.

I’m sorry we don’t have a great example of this online to point you to. I’ll try and get some examples like this put into the dry-view repo at some point, but unfortunately I don’t think it’ll be for at least a few weeks.


#3

Thanks for the response, Tim. Much appreciated.