├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Controller.php └── RenderMany.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | .idea/ 3 | *~ 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Skliar Ihor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RenderMany extension for Yii Framework 2 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/igogo5yo/yii2-render-many/v/stable)](https://packagist.org/packages/igogo5yo/yii2-render-many) [![Total Downloads](https://poser.pugx.org/igogo5yo/yii2-render-many/downloads)](https://packagist.org/packages/igogo5yo/yii2-render-many) [![License](https://poser.pugx.org/igogo5yo/yii2-render-many/license)](https://packagist.org/packages/igogo5yo/yii2-render-many) [![Dependency Status](https://www.versioneye.com/user/projects/56655361f376cc003d000a91/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56655361f376cc003d000a91) 4 | 5 | Yii Framework 2 extension for render many views in one action (best solution for landing pages or pages with many content blocks) 6 | 7 | Please submit issue reports and pull requests to the main repository. 8 | For license information check the [LICENSE](LICENSE.md)-file. 9 | 10 | Installation 11 | ------------ 12 | 13 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 14 | 15 | Either run 16 | 17 | ``` 18 | php composer require --prefer-dist igogo5yo/yii2-render-many 19 | ``` 20 | 21 | or add 22 | 23 | ``` 24 | "igogo5yo/yii2-render-many": ">=1.0" 25 | ``` 26 | 27 | to your `composer.json` file 28 | 29 | 30 | Example 31 | ---- 32 | 33 | use trait 34 | ```php 35 | ... 36 | class MyController extends Controller { 37 | use igogo5yo\rendermany\RenderMany; 38 | 39 | public function actionIndex() 40 | { 41 | 42 | return $this->renderMany([ 43 | 'sliderSection' => [ 44 | 'slides' => ['img1.jpg', 'img3.jpg', 'img3.jpg'] 45 | ], 46 | 'contentSection' => [ 47 | 'title' => 'My post', 48 | 'description' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry...', 49 | ], 50 | 'partnersSection' => [ 51 | 'partners' => [ 52 | ['link' => '#', 'name' => 'partner 1'], 53 | ['link' => '#', 'name' => 'partner 2'], 54 | ['link' => '#', 'name' => 'partner 3'], 55 | ] 56 | ], 57 | 'footer' //without passing variables 58 | ]); 59 | } 60 | } 61 | ``` 62 | 63 | or extend your controller 64 | ```php 65 | 66 | class MyController extends igogo5yo\rendermany\Controller { 67 | public function actionIndex() 68 | { 69 | 70 | return $this->renderMany([ 71 | 'sliderSection' => [ 72 | 'slides' => ['img1.jpg', 'img3.jpg', 'img3.jpg'] 73 | ], 74 | 'contentSection' => [ 75 | 'title' => 'My post', 76 | 'description' => 'Lorem Ipsum is simply dummy text of the printing and typesetting industry...', 77 | ], 78 | 'partnersSection' => [ 79 | 'partners' => [ 80 | ['link' => '#', 'name' => 'partner 1'], 81 | ['link' => '#', 'name' => 'partner 2'], 82 | ['link' => '#', 'name' => 'partner 3'], 83 | ] 84 | ], 85 | 'footer' //without passing variables 86 | ]); 87 | } 88 | } 89 | ``` 90 | 91 | also you can use partial rendering 92 | ```php 93 | public function actionIndex() 94 | { 95 | 96 | return $this->renderMany([ 97 | 'sliderSection' => [ 98 | 'slides' => ['img1.jpg', 'img3.jpg', 'img3.jpg'] 99 | ], 100 | 'wrapper' => [ 101 | 'innerRenders' => $this->renderManyPartial([ 102 | 'innerView1' => [ 103 | 'param1' => 'some data 1'. 104 | 'param2' => 'some data 2' 105 | ], 106 | 'innerView2' //without passing variables 107 | ]) 108 | ], 109 | 'footer' //without passing variables 110 | ]); 111 | } 112 | ``` 113 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "igogo5yo/yii2-render-many", 3 | "description": "Yii Framework 2 extension for render many views in one action (best solution for landing pages or pages with many content blocks)", 4 | "keywords": [ 5 | "render", 6 | "many", 7 | "views", 8 | "igogo5yo", 9 | "yii2", 10 | "framework" 11 | ], 12 | "type": "yii2-extension", 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "Skliar Ihor", 17 | "email": "skliar.ihor@gmail.com" 18 | } 19 | ], 20 | "require": { 21 | "yiisoft/yii2": "*" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "igogo5yo\\rendermany\\": "src" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Controller.php: -------------------------------------------------------------------------------- 1 | 8 | * @version 1.3 9 | */ 10 | trait RenderMany { 11 | /** 12 | * @param $views array of views options 13 | * [ 14 | * 'view1' => [ params ], 15 | * 'view2' => [ params ], 16 | * 'view3', 17 | * 'view4' 18 | * ... 19 | * ] 20 | * 21 | * @return string imploded views array 22 | */ 23 | public function renderMany(array $views, $partial = false) { 24 | $renders = []; 25 | foreach ($views as $view => $params) { 26 | if (is_int($view) && is_string($params)) { 27 | $view = $params; 28 | $params = []; 29 | } 30 | 31 | $renders[] = $this->renderPartial($view, $params); 32 | } 33 | 34 | $html = implode("\r", $renders); 35 | 36 | return $partial ? $html : $this->renderContent($html); 37 | } 38 | 39 | /** 40 | * Alias for RenderMany::renderMany([], true); 41 | */ 42 | public function renderManyPartial(array $views) { 43 | return $this->renderMany($views, true); 44 | } 45 | } 46 | --------------------------------------------------------------------------------