NodeJS, Reuasble Modules: Use Partials OR Include in Layout Page?

Hey guys,

In my project I have a few areas that I will have to call the same procedures.
By saying procedures I mean:

  • Add New Client
  • Add New Product
  • and a few more with similar method/result

The way that I started working on this is:

  • In my content page added the datasource components (ServerConnects / DataViews for easy filtering and DataDetail for updating a record)
  • Then I call a modal in case of
    1)adding a new record
    2)updating a record (pass the current id to the datadetail and populate the data in my form)

So,this morning I asked my self:

"-Wait.... In every page that I will need to do the same thing I will have to copy/paste all these modal and their datasources????
-Maybe this can be achieved using nodeJS partials?"

So, I tried before a while and kind of failed...
It seems to work if the button that triggers the Modal is inside a simple element BUT when I click it from within another modal thaen there is a backdrop and both modals disapear...
Tried to call first the .toggle() method for the already open Modal and then the .show() for the partial Modal but... NO LUCK!

And of course, the content of the partial is not reachable from the content page...

Does anybody thinks that this is doable?
Can you point me to a direction?

Thanks in advance

Hi @famousmag,

This may be possible, but I have never tried Partials for this purpose. In NodeJS, I add almost all the Server Connects, Data Details, Data Views and Modals in the layout page, unless these components are not needed across the content pages. Components added in a layout page are available on all the content pages.


Thanks Buddy!! You are correct, didn't think about it...

But this way you may end-up with a giant layout page...
I suppose this doesn't matter, right?

1 Like

The layout page certainly gets longer, but it doesn't matter. Add the Modals after the footer section and just before the closing body tag.

The benefit is that these components become available across the content pages attached to that layout, and you are maintaining only one set of code rather than the same code on multiple pages.


Thaks Buddy!!

And I suppose I'm kind of clever... WTF!!!
That's why I keep saying to myself... "Stop empty your mind and rething from scratch!!"

1 Like

You're welcome, @famousmag.

I can completely relate to this situation; I too have gone down the rabbit hole many times :slight_smile:

1 Like