Comments (9)
Hi, as a pug port we provide pug js equivalent, the dash allow raw code, it's the pug native feature, in pug js raw code is js code, in this port, it's PHP we just translated it. Ranges are also available in this way:
each i in range(0, $j - 1)
You can also use while, this is the pug native way to do: http://jade-lang.com/reference/iteration/
The dash in pug is nearly the same than the arobase in blade it's nothing more than a PHP injection. It just use for: and endfor; And in Pug we do not want some things like end keyword because pug is structured by indentation. (You will meet the same problem if you try to use ´´´for´´´ this way in the native js pug.)
It you get a too complex loop to do in Pug, you probably should do it in your controller, in a filter, or elsewhere but as you say it's for html and the view and the application logic should not be mixed, so in my humble opinion, the features provided by Pug are just enough to fit the need. If you're stuck with some tricky template you can ask I will try to give you the "clean way".
PS: you're not the very first there are closed issue here and on jade the previous name. Thanks for support.
from pug.
thanks for your answer ;)
as you say, pug has raw mode, I agree with you, but it's for javascript.
not php. when I copy some template from my nodejs project,
it doesn't work, this is the point.
php is php, javascript is javascript,
pug-php should not break pug's js support
then pug-php should be the plus feature,
like some keyword @foreach, @if, @extends, @layout,
how do you think about it?
from pug.
First, if you want strictly compatible template from pugjs, use a wrapper (php execution of pug-cli). The problem with this method is that you have to pass flat data, you will not be able to pass an object of a custom User class for example. Pug-php give a way to use dynamic object and native php functions in pug templates. For the rest, we try to keep Pug-php as close as possible to the js version.
if
, layout
(see block
) and extends
exist, so no need of @ new keywords, and foreach
exist as each
and allow you to do some repetitive structures.
However, I think about a way to customize the engine to add your own rules as it is possible in blade and twig.
from pug.
Hi, I see the point (at last). I never notice this works with pug-php:
- j = 4
- for ($i = 0; $i < $j; $i++)
p hello #{i}
I permit myself to rename your issue for classification. The dash will be keeped for retrocompatibility. And the trick can be very usefull and I think it's used, so I would not break templates that use it.
My recommandation for those kind of cases is to use the dash only for variables initializations and you should initialize only with static values. Use as few raw code and dynamic expression as possible in your pug templates.
But what you want (a real for
keyword) will be possible in 2.0 with customization.
You will have to do something like that:
$pug = new Pug();
$pug->addKeyword('for', function ($args) {
return array(
'beginPhp' => 'for (' . $args . ') {',
'endPhp' => '}',
);
});
And you will be able to use it in your templates in a nice pug style:
for $i = 0; $i < $j; $i++
p hello #{i}
from pug.
@kylekatarnls thanks for all
from pug.
Pug keywords are out: https://github.com/pug-php/pug#supports-for-custom-keywords
Soon I will publish a 2.0.0 pre-release with this new feature.
from pug.
2.0.0 is out. Do not hesitate, post new issue if you have any suggestion for keywords or other.
from pug.
@kylekatarnls Hey Kyle, I know this is a bit old. I am coming from BKWLD/laravel-pug#2 , I am having issues passing through values for customKeyword, I have essentially tried the arguments used for the addKeyword function, but can't get it to work. Can you please add some documentation for passing custom keywords?
from pug.
There is documentation: https://github.com/pug-php/pug#supports-for-custom-keywords
What's your code, the behaviour you get and the behaviour you expect?
from pug.
Related Issues (20)
- syntax error, unexpected 'idx' (T_STRING), expecting ';' HOT 1
- Support template literals HOT 1
- Undefined variable fatal error appears on quoted Vue.js variable HOT 13
- Ternary conditional operator fails with linebreak HOT 6
- read-only cache directory HOT 20
- Undefined variable when using mixin with concatenation HOT 3
- Accessing helper functions in a namespace HOT 4
- PHP 7.4 with Pug 2.7.5 minor correction HOT 3
- Compatibility problem with laracast HOT 4
- Interpolation does not support null coalescing operator HOT 4
- enable_profiler => true shows php notices (undefined index) HOT 5
- Apostrophe is escaped HOT 2
- Option to disable html minficiation HOT 1
- Bug when using combinaison of mixins with block in iteration
- Incompatibility with composer 2.0 HOT 1
- Tag Name error HOT 5
- PHP 8 support? HOT 3
- How do i convert back to HTML and keep the variable intact? HOT 1
- Deprecation warning in PHP 8.1 for null values HOT 1
- Pug 2.7.6 minor correction to avoid warning with block append usage 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.