承接 ardentic/squeezer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ardentic/squeezer

最新稳定版本:v1.0.3

Composer 安装命令:

composer require ardentic/squeezer

包简介

Squeezer is an extension to Laravel's templating engine Blade. It adds powerful features like @embed, @class and @style.

README 文档

README

Squeezer is an extension to Laravel's templating engine Blade. It adds powerful features like @embed, @class and @style.

Install with composer

In your favorite terminal app just run:

composer require ardentic/squeezer

Add Squeezer to Laravel

In config/app.php add the following:

'providers' => [
  Ardentic\Squeezer\SqueezerServiceProvider::class
]
'aliases' => [
  'Squeezer' => Ardentic\Squeezer\SqueezerFacade::class
]

Examples

Some basic examples of what you can achive with Squeezer.

@style

@style will allow you to generate style attributes as a string from a named array.

Example

<?php
  $styles = [
    'top' => '0',
    'left' => '0',
    'background-color' => '#ccc'
  ];
?>

<div @style($styles)></div>

This will generate the following result:

<div style="top: 0; left: 0; background-color: #ccc;"></div>

@class

@class will allow you to generate a class list as a string from a named array.

Example

<?php
  $classes = [
    'button',
    'button--wide'
    'is-active' => true,
    'is-disabled' => false
  ];
?>

<div @class($classes)></div>

This will generate the following result:

<div class="button button--wide is-active"></div>

@embed

@embed will allow you to embed view components inside other view components much like @extends work in Blade. While @section and @extends can't be nested, @embed can.

@embed will also allow you to pass local variables and hook up ViewComposers to the component you are embedding.

Basic concept of @embed

wrapper.blade.php

<div class="wrapper">
  @block('content')
</div>

component.blade.php

@embed('wrapper')
  @block('content')
    <div class="component"></div>
  @endblock
@endembed

This will generate the following result:

<div class="wrapper">
  <div class="component"></div>
</div>

Passing local variables with @embed

wrapper.blade.php

<div class="wrapper" data-layout="{{ $layout }}">
  @block('content')
</div>

component.blade.php

@embed('wrapper', ['layout' => 'slim'])
  @block('content')
    <div class="component"></div>
  @endblock
@endembed

This will generate the following result:

<div class="wrapper" data-layout="slim">
  <div class="component"></div>
</div>

Using @embed with a ViewComposer

AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
  public function boot()
  {
    view()->composer('wrapper', function($view) {
      $view->with('layout', 'slim');
    });
  }

  public function register()
  {
    //
  }
}

wrapper.blade.php

<div class="wrapper" data-layout="{{ $layout }}">
  @block('content')
</div>

component.blade.php

@embed('wrapper')
  @block('content')
    <div class="component"></div>
  @endblock
@endembed

This will generate the following result:

<div class="wrapper" data-layout="slim">
  <div class="component"></div>
</div>

统计信息

  • 总下载量: 1.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-26