Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could u please add some sample #2

Closed
yozman opened this issue Nov 7, 2016 · 21 comments
Closed

could u please add some sample #2

yozman opened this issue Nov 7, 2016 · 21 comments

Comments

@yozman
Copy link

yozman commented Nov 7, 2016

could u please add some sample at README.md?

@nmsmith22389
Copy link

If it's pug example code you are looking for then just check out here.

@fidgetwidget
Copy link

I think the kinds of examples that would be helpful here are how to use blade directives in the pug syntax.

from what I can tell, you'll want to use the :escaped filter and you'll need to handle both the beginning and ending statements for each directive.

eg.

ul
  :escaped @foreach($array as $value)
  li {{ $value }}
  :escaped @endforeach

It would be nice if this had some custom keyword support for them
eg.

$pug->addKeyword('foreach', function ($args) {
    return array(
        'beginPhp' => '@foreach (' . $args . ')',
        'endPhp' => '@endforeach',
    );
});

@nmsmith22389
Copy link

Yeah I suppose I agree... It's not a very elegant solution because I feel like it messes some of the blade stuff up and doesn't work as well as I would like it to. The lack of docs isn't very helpful either.

ಠ_ಠ

@weotch weotch closed this as completed Feb 28, 2017
@weotch
Copy link
Member

weotch commented Feb 28, 2017

I'm not a blade user myself. If there is something you learned that wasn't immediately obvious, feel free to PR the README with it.

@partounian
Copy link

partounian commented Mar 26, 2017

I noticed you closed this on grounds of the PR to README, but could the addKeyword functionality be added? Or does anyone know how to use the customKeywords passthrough for this? I have tried inputting the arguments of the above command in the passthrough array and with slight variations to no avail. Also noticed, I can't use a php function inside a tag/value (notable, the csrf_token function).

I have managed to escape the inline value by doing this,
input(type='hidden', value!="'. csrf_token() .'", name='_token')
but the function doesn't get compiled into the value it comes out as plain text.

Note for others: Using the {{ csrf_field() }} works.

@weotch @fidgetwidget

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Mar 26, 2017

addKeyword is not what you need here, then it neither the syntax to pass value, to call global functions just use:

input(type='hidden' value!=csrf_token() name='_token')

You can also use the raw code with:

- csrf_field()

If the functions are not global, you will have to pass it from your framework to view variables, see the helpers documentation: https://github.com/pug-php/pug#php-helpers-functions

@Konafets
Copy link

Just want to add some of my experience with PUG and Blade:
It does not work or on a very inconvenience level. The code looks really bad and the mixture of Blade and PUG does not always work. Mainly because of the expected indention of PUG.

However, I found another nice way to use PUG with Laravel: VueJs and VueLoader. It is described here: https://vuejs.org/v2/guide/single-file-components.html

I just leave it here as an alternative.

@kylekatarnls
Copy link
Collaborator

Vue.js is a really different approach. For example, to inject data in template since, you send data and template and let the client compile it. With pug server-side, you send to the client rendered HTML with data already compiled in it.

But what I really not undrestand is what mix blade an pug? It seems redundant to me (each, mixins, expression insertion), all exist in pug.

@Konafets
Copy link

Yes, the approach is different. Regarding the mix of blade and pug: I thought you are bound to use Blade for things like iterations and did not looked carefully to the pug documentation. Thanks for pointing it out.

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Mar 27, 2017

Blade iterations are very verbose. And Pug iterations indent is meaningful. I recommend:

each item in items
  p=item

over any blade wrapping for iterations.

Also prefer to well learn and use 1 template engine rather than use several and miss nice features.

@partounian
Copy link

Just starting off I am using pug to simply have the HTML look clean while using blade for the logic.

@partounian
Copy link

Also the reason I was asking about custom keywords is so I can use the blade logic without :escaped

@kylekatarnls
Copy link
Collaborator

What do you call blade logic? Sections is block in pug, component is mixin, can you tell me what feature of blade you would implement as a new keyword? Because both blade and pug are very complete template engines and I don't see what would miss. Are you looking for the $loop information feature?

@partounian
Copy link

Foreach for example.

@kylekatarnls
Copy link
Collaborator

As I already say here: #2 (comment) and here: #2 (comment) foreach exists in pug:
each item in items is exactly the same as @foreach ($items as $item), do not reinvent the wheel, take benefit of existing features.

We should not implement blade helpers until having a good reason to do it.

@partounian
Copy link

My apologies, I thought the foreach in pug would only be using JS variables, I did not realize it is integrated that nicely with Laravel's PHP.

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Mar 29, 2017

Glad it works for you now. :)

@Konafets
Copy link

What is the equivalent of @yield and @stack in pug?

@kylekatarnls
Copy link
Collaborator

See block and append. Should acheive the same goal.

@Konafets
Copy link

Konafets commented Apr 13, 2017

Thanks, one more question:

I have this code

html(lang="{{ config('app.locale') }}")

According to this comment the usual moustache syntax should work, but it does not. I got

<html lang="{{ config('app.locale') }}">

in the FE.

I also tried - config('app.locale'), which does not work out neither.

@fdorantesm
Copy link

You don't need to use moustaches.

`html(lang=config('locale'))

weotch pushed a commit that referenced this issue Aug 29, 2017
Cover ServiceProvider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants