Last active
April 16, 2020 15:57
-
-
Save JaminFarr/0b875916b39bf83c4b06 to your computer and use it in GitHub Desktop.
Laravel Blade mixins for jade for use with laravel-elixir-jade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//- For use with https://github.com/CREEATION/laravel-elixir-jade | |
mixin blade() | |
='\r\n' | |
block | |
='\r\n' | |
mixin phpblock() | |
!='\r\n<?php ' | |
block | |
!='\r\n?>' | |
mixin php(php) | |
if (php) | |
!='\r\n<?php ' + php + ' ?>' | |
else | |
!='\r\n<?php ' | |
block | |
!=' ?>' | |
mixin if(op) | |
+blade @if(!{op}) | |
block | |
+blade @endif | |
//- +else and +elseif must be one indentation from +if | |
mixin elseif(op) | |
+blade @elseif(!{op}) | |
block | |
mixin else() | |
+blade @else | |
block | |
mixin unless(op) | |
+blade @unless(!{op}) | |
block | |
+blade @endunless | |
mixin for(terms) | |
+blade @for(!{terms}) | |
block | |
+blade @endfor | |
mixin foreach(terms) | |
+blade @foreach(!{terms}) | |
block | |
+blade @endforeach | |
mixin forelse(terms) | |
+blade @foreach(!{terms}) | |
block | |
mixin empty() | |
+blade @empty | |
block | |
+blade @endforelse | |
mixin while(test) | |
+blade @while(!{test}) | |
block | |
+blade @endwhile | |
mixin yield(name, defaultContent) | |
if defaultContent | |
+blade @yield('!{name}', '!{defaultContent}') | |
else | |
+blade @yield('!{name}') | |
mixin include(file, data) | |
if data | |
+blade @include('!{file}', !{data}) | |
else | |
+blade @include('!{file}') | |
mixin extends(file) | |
+blade @extends('!{file}') | |
mixin section(name, ender) | |
+blade @section('!{name}') | |
block | |
if (ender) | |
+blade @#{ender} | |
else | |
+blade @stop | |
mixin sectionshow(name) | |
+section(name, 'show') | |
block | |
mixin sectionoverwrite(name) | |
+section(name, 'overwrite') | |
block | |
mixin sectionstop(name) | |
+section(name) | |
block |
Hello, I really love these mixins, thank you for making it, very helpful.
I've noticed that when I use the include mixin it passes the data as a string.
For example, this:
mixin include(file, data)
if data
+blade @include('!{file}', '!{data}')
else
+blade @include('!{file}')
+include("view.name", "['data' => 'something']")
Outputs this:
@include("view.name", "['data' => 'something']")
In Laravel it shows me an error because it's trying to pass the data as a string instead of an array.
I changed the mixin to this (removed the single quotes):
mixin include(file, data)
if data
+blade @include('!{file}', !{data}) // <= I removed the single quotes
else
+blade @include('!{file}')
+include("view.name", "['data' => 'something']")
And now it outputs:
@include("view.name", ['data' => 'something'])
And that fixed it for me, in case someone has the same problem.
Cool mixins, I always use them.
Greetings.
Two years later and I've made the change @asaelx suggested. Sorry about that.
@FreedomKnight I'm sure you're not still waiting on an answer but here it is anyway. Just needs quotes around the blade/php values.
+foreach('$vars as $var')
p {{ $var }}
outputs
@foreach($vars as $var)
<p>{{ $var }}</p>
@endforeach
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, Can +foreach($vars as $var) escape "as" token?
the warning message said it don't accept "as".
Or I don't know your design.