Вопрос

Why I can't thing a view like part of a module?.

In .NET you have the view and the code behind. Sometimes we need to do somehing that match with this logic like grid with a widget inside each cell. Usually a widget have a little nice box with a title and the content, with a little logic, how I can include a partial like that to another view like that.

@extends('jarvis.admin._layouts.default')

@section('title')
  Dashboard
@stop

@section('main')
<div class="row-fluid">
    <div class="span4">
        @yield('first')

        <div class="jarviswidget" id="widget-id-00">
            <header>
                <h2>{{ $widget['title'] }}</h2>                           
            </header>
            <div>
                <div class="jarviswidget-editbox">
                    <div>
                        <label>{{ ucfirst(Lang::get('strings.title')) }}:</label>
                        <input type="text">
                    </div>
                    <div>
                        <label>{{ ucfirst(Lang::get('strings.style')) }}</label>
                        <span data-widget-setstyle="red" class="red-btn"></span>
                        <span data-widget-setstyle="green" class="green-btn"></span>
                        <span data-widget-setstyle="purple" class="purple-btn"></span>
                        <span data-widget-setstyle="black" class="black-btn"></span>
                        <span data-widget-setstyle="darkgrey" class="darkgrey-btn"></span>
                    </div>
                </div>
                <div class="jarviswidget-timestamp"></div>
                <div class="inner-spacer"> 
                    <!-- content goes here -->
                    @yield('wg_content')

                    Content

                </div>
            </div>
        </div>

    </div>
    <div class="span4">
        @yield('second')

        <div class="jarviswidget" id="widget-id-00">
            <header>
                <h2>{{ $widget['title'] }}</h2>                           
            </header>
            <div>
                <div class="jarviswidget-editbox">
                    <div>
                        <label>{{ ucfirst(Lang::get('strings.title')) }}:</label>
                        <input type="text">
                    </div>
                    <div>
                        <label>{{ ucfirst(Lang::get('strings.style')) }}</label>
                        <span data-widget-setstyle="red" class="red-btn"></span>
                        <span data-widget-setstyle="green" class="green-btn"></span>
                        <span data-widget-setstyle="purple" class="purple-btn"></span>
                        <span data-widget-setstyle="black" class="black-btn"></span>
                        <span data-widget-setstyle="darkgrey" class="darkgrey-btn"></span>
                    </div>
                </div>
                <div class="jarviswidget-timestamp"></div>
                <div class="inner-spacer"> 
                    <!-- content goes here -->
                    @yield('wg_content')

                    Content

                </div>
            </div>
        </div>

    </div>
    <div class="span4">
        @yield('third')

        <div class="jarviswidget" id="widget-id-00">
            <header>
                <h2>{{ $widget['title'] }}</h2>                           
            </header>
            <div>
                <div class="jarviswidget-editbox">
                    <div>
                        <label>{{ ucfirst(Lang::get('strings.title')) }}:</label>
                        <input type="text">
                    </div>
                    <div>
                        <label>{{ ucfirst(Lang::get('strings.style')) }}</label>
                        <span data-widget-setstyle="red" class="red-btn"></span>
                        <span data-widget-setstyle="green" class="green-btn"></span>
                        <span data-widget-setstyle="purple" class="purple-btn"></span>
                        <span data-widget-setstyle="black" class="black-btn"></span>
                        <span data-widget-setstyle="darkgrey" class="darkgrey-btn"></span>
                    </div>
                </div>
                <div class="jarviswidget-timestamp"></div>
                <div class="inner-spacer"> 
                    <!-- content goes here -->
                    @yield('wg_content')

                    Content

                </div>
            </div>
        </div>

    </div>
</div>

<div class="row-fluid">
    <div class="span12">
    </div>
</div>
@stop

Where each @yield will load a small widget processing the little logic or even another template with another nested views.

For example @yield('first') will load a box that is another template with a yield inside, and a variable as title. This nested yield will have another yield or the content... then the same box we use for the box will be used another time to render @yield('second') with another title and another content, that maybe use the same as the first yield.

I don't understand how to make this cascade with blade template system. Is there a way to do something similar?

I know is complicated but if you ever used .net, you could understand what I mean.

Thanks and sorry for my english.

Do that have similarities with the HMVC model, but is not the same.

Это было полезно?

Решение

I found the solution...

Is a little complicated to explain here but I'm going to do my best.

Try this:

default template (default.blade.php)

<!DOCTYPE html>
  <html lang="en">
    <head></head>

    <body>

      <div class="fluid-container">

        @yield('main')

      </div>

    </body>
  </html>

default content template (mypage.blade.php)

@extends('_layouts.default')

@section('main')
    <div id="widget-grid">
        <div class="row-fluid">
            <article class="span12">
                @include('_modules.mymodule')
            </article>
        </div>
    </div>
@stop

module template (mymodule.blade.php)

We send some variables to the shared template widget

@extends('admin._partials.widget', array('widget' => array('title' => 'title', 'id' => 'some_id', 'style' => 'your: style')))

@section('wg_content')
  <!-- Your widget content goes here -->
@overwrite

shared template (widget.blade.php)

Your title $widget['title']
Your id $widget['id']
Your style $widget['style']
<!-- content -->
@yield('wg_content')

The views directory tree would be:

views
  _layouts
    default.blade.php
  _partials
    widget.blade.php
  _modules
    mymodule.blade.php
  page
    mypage.blade.php

Now when you make the view from the controller you should call mypage.

The magic directive is @overwrite in the bottom of module template.

Now when you call the module, the system get the widget template and wrap mymodule, then add this to the page and finally wrap everything within default which is the main template.

This help you to share a template with others. I know you have question, ASK! XD

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top