-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
For render as PHP structure #22
Comments
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. |
thanks for your answer ;) as you say, pug has raw mode, I agree with you, but it's for javascript. then pug-php should be the plus feature, how do you think about it? |
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.
However, I think about a way to customize the engine to add your own rules as it is possible in blade and twig. |
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 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} |
@kylekatarnls thanks for all |
* Implement custom keywords * Allow to customize the class attribute * Document custom keywords
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. |
2.0.0 is out. Do not hesitate, post new issue if you have any suggestion for keywords or other. |
@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? |
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? |
hey first of all,
thanks for make pug for php 馃憤
I have some ideas for pug.
I think pug is for html, just for html
so what does it mean?
in
pug-php
,- for ($i = 0; $i < $j; $i++)
render asPHP
structit not right at all
the right way use pug in php
it should base on orther php template engine like
blade
,twig
how do u think about it?
The text was updated successfully, but these errors were encountered: