Reusing partial content with other content in the same view

As described in the Sails.js documentation:

All your local residents will be automatically sent to the particle.

Therefore, I was wondering how I can use the same partial several times in the same view, but with different content.

Let's say I have a list of the 3 best users and a list of the latest 3 users. Lists have the same HTML structure and the same CSS style, but their content is different.

How can I use the same partial ones (e.g. user / list.ejs) to display both lists? Does anyone know if there is a way to pass specific data to partial rather than local representations?

Thanks in advance.

Dennis

+4
source share
1 answer

Sails uses the ejs-locals library to process partial files, which allows you to send partial parameters as the second argument. So in your template you can:

<h1>Top users: </h1>
<p>
  <%= partial('user/list.ejs', {users: topUsers}) %>
</p>

<h1>New users: </h1>
<p>
  <%= partial('user/list.ejs', {users: newUsers}) %>
</p>

for different values usersinside the part user/list.ejs, provided that you specify topUsersand newUsersas local when you show a view that includes a partial, i.e. in the action of your controller:

res.view("myView", {topUsers: [array of users], newUsers: [array of users]});
+2
source

Source: https://habr.com/ru/post/1569224/


All Articles