Giter VIP home page Giter VIP logo

Comments (4)

baryshev avatar baryshev commented on August 28, 2024

By default all variables available in all templates hierarchy. But it can be overwritten. You don't need to pass user variable into include in your case.

from ect.

RandomEtc avatar RandomEtc commented on August 28, 2024

Right. Sorry.

The use-case I'm thinking of is when I want to use an include to render an item in a collection, so I want to pass some one-off parameters to the included template as well as the parameters from the calling page.

So if I do:

res.locals.users = [ { name: 'RandomEtc' }, { name: 'baryshev' } ]
res.locals.otherInfo = 'foo'
res.render('page')

And in page.ect I do:

<% for user, i in @users: %>
  <% include 'user', { user: user, index: i } %>
<% end %>

I'd like user.ect to have access to @otherInfo. Currently I must pass it explicitly:

<% for user, i in @users: %>
  <% include 'user', { user: user, index: i, otherInfo: @otherInfo } %>
<% end %>

I should have used this example previously, apologies.

...

Thinking about it, I guess I could just expose an extend (or inherit or merge) helper method and do this:

<% for user, i in @users: %>
  <% include 'user', @extend(this, { user: user, index: i }) %>
<% end %>

But I'm wondering if this would be useful default behavior?

from ect.

baryshev avatar baryshev commented on August 28, 2024

Sorry, there is no native way to merge parameters right now. Merge may cause performanse issues in this context.

from ect.

RandomEtc avatar RandomEtc commented on August 28, 2024

OK I'll write a helper.

from ect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.