Giter Club home page Giter Club logo

Comments (9)

kylekatarnls avatar kylekatarnls commented on May 23, 2024

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.

yozman avatar yozman commented on May 23, 2024

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.

kylekatarnls avatar kylekatarnls commented on May 23, 2024

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.

kylekatarnls avatar kylekatarnls commented on May 23, 2024

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.

yozman avatar yozman commented on May 23, 2024

@kylekatarnls thanks for all

from pug.

kylekatarnls avatar kylekatarnls commented on May 23, 2024

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.

kylekatarnls avatar kylekatarnls commented on May 23, 2024

2.0.0 is out. Do not hesitate, post new issue if you have any suggestion for keywords or other.

from pug.

partounian avatar partounian commented on May 23, 2024

@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.

kylekatarnls avatar kylekatarnls commented on May 23, 2024

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)

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.