Comments (14)
any update?
from pug-loader.
For those of you who seek a hack for the for loop - the solution in #47 works if you define the var in the locals
:
- locals namesArray = ['Amir', 'Tugi']
- each element in locals.namesArray
- locals.element = element
include path/to/file // <-- The file will now be able to access the variable via #{element}
With that said, any progress on the real official solution yet?
from pug-loader.
@ryoikarashi you can use my fork for now https://github.com/antpaw/pug-loader
from pug-loader.
@damassi this is the fork i have used to transfer my ezel based setup to webpack. The only downside I can see is that the bundle size will get bigger (extremely bigger, in extrem cases), but it uses the same convention as the browserify compiler ect, so coming from other compilers should not cause noticeable size difference. But it could be done more efficient if you would somehow "collect" all the variable form the closer scope and pass them to the included template function instead of inlining it. I think this will require a major change in the internal workings of pug, and am not even sure if the "collecting" part is possible.
from pug-loader.
@antpaw - Can confirm your fork fixed the issue. Thanks again 👍
from pug-loader.
I've found this answer #47 I strongly disagree with this idea.
This is a important template feature and using locals
is not documented in any way in pug/jade documentation. Setting something on a global object locals
will always lead to side effects that might cause unexpected behaviour. It might be not a big deal for client side, but in a isomorphic app where partials have to work on node as well you might be modifying unintentionally object references for different requests.
The best fix for this would be if pug had two different syntaxes for include that let programmers decide to inline or to require the template. Or a syntax that provides a way to define variables that should be passed down to the include along with already set variables.
Chances for this to happen are almost zero i would say, so I suggest that the library should inline every "include".
from pug-loader.
I guess @sokra (who initially implemented template inlining) didn't realize this incompatibility. I agree with your evaluation, and I'm okay with the idea of adding a require
plugin in pug-loader. But until such a keyword is implemented, I'm inclined to keep the status quo as it is, so that existing Jade (and jade-loader) users can more easily upgrade to Pug.
from pug-loader.
Hello everyone.
I don't know why this happen, but if in included file we call any mixin variables that we passed returned their value.
For example:
//- empty.pug
mixin empty()
if false
p nothing here
//- template1.pug
include empty.pug
for myScopedVar in [1, 2, 3]
include low_level_template
//- low_level_template.pug
+empty()
p= myScopedVar
And this work. But if we just delete line with +empty()
mixin call, myScopedVar
return undefined
.
Maybe this can help someone.
from pug-loader.
@TimothyGu - Any tips as to how to go about implementing this would be appreciated. This issue just put a hard stop on our large webpack refactor
from pug-loader.
Thanks @antpaw - will look into it!
from pug-loader.
Any movement on getting this fixed?
from pug-loader.
Any progress on this?
For now I will use @antpaw 's fork which seems to work great.
from pug-loader.
It would be great if the docs could be updated to relfect this. Took me a while to figure out what was happening here. @AmirTugi's fix worked perfectly for me.
from pug-loader.
Following simple example work with the pug-loader:
- var items = ['Hello', 'pug!']
each str in items
include ./include-var-str
file include-var-str.pug
:
i= str
The local variable str
defined in each in
cycle is available in included template.
Output:
<i>Hello</i><i>pug!</i>
from pug-loader.
Related Issues (20)
- require a variable HOT 2
- “include” correctly imports content, but “extends/block” yields no content or errors HOT 1
- Can't get some Mixins correctly loaded: Empty mixins
- Interpolation not working
- 'module' is not a known element error HOT 7
- how to remove comments in pug template?
- Can not use require with variable in mixin HOT 6
- 'Module not found: Error: Can't resolve` when use a mixin and require on same file HOT 3
- Is this package still being maintained? HOT 43
- any support for webpack-4 or webpack-5 HOT 6
- warning " > [email protected]" has incorrect peer dependency "pug@^2.0.0". HOT 6
- Unbuffered Code Issue with variables declared at beginning of pug template when using loader HOT 3
- Raise error manually
- Angular 11 postinstal script error(solution)
- Includes and or mixins sometimes do not trigger changes in parents while watching HOT 1
- Pug > 3, pug-loader error. HOT 3
- pug-loader no longer maintained? HOT 1
- esbuild alternative HOT 4
- load a CSS file in pug file HOT 6
- Npm Audit report HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pug-loader.