Laravel 5.4 render parent view before child view - laravel

Is it possible to force laravel to execute the parent view then the child view ? I use a master view with some view composers to create a menu and set some variables, then in my sitemap subview, because the master view is computed after I end up having my menu not created yet.
#extends('layout.master')
#section('content')
{{-- Render this after layout.master --}}
#endsection
Maybe I missed some possibility here.

If you watch code that blade generate in storage/framework/views/some_name.php you can see next code:
<?php echo $__env->yieldContent('content'); ?>
It`s working something like PHP inlcude, when code come to this line it come in to this file with content.
That`s why you can not load master view and then subview.

Related

extending laravel blade comming to top

i am an absolute beginner in laravel i have a basic structure for now, there is an app template which contains the structure of the view i.e
head
navbar
#yield("content")
footer
now the structure is working fine now for some specific pages i have to include google map the map blade is placed inside includes/map.blade.php this is my index blade
#extends("app")
#section("content")
the content goes here
#extends("includes.map")
#endsection
basically after the content i want to put the map so that it comes above footer but somehow whenever i try to extent it it always comes at the top
If you want to include the map then it should be #include (doc):
#extends("app")
#section("content")
the content goes here
#include("includes.map")
#endsection
You cannot use two extends.
Instead of #extends("includes.map") use #include("includes.map")

Undefined variable in a child view

i have created a master layout and extending it to a child view this way:
master.blade.php (short version):
<body>
#section('content')
#foreach($articles as $article)
{{ $article->title }}
#endforeach
#show
</body>
Then a child view called child.blade.php:
#extends('master')
#section('content')
<p>Some static content</p>
#stop
However, when i am visiting a page with child.blade.php i am getting an error:
Undefined variable: articles (View: /app/views/master.blade.php)
Why am i getting this error? I don't have this variable in my child.blade.php, so i guess - child view inherits master's variables by default? But why? I didn't used #parent
What you really want is View Composer. This way you can share the data between several views without repeating yourself. In your case whenever your child.blade.php view will be rendered additional data you want to pass will be added.
Read more at docs: View Composers
If you don't want to use View composer you need to pass the articles to your child.balde.php

How do I manually theme Views in Drupal 7?

I am new to drupal and I am trying to figure out how to theme Views. I currently have a content type called Category with the following fields:Title, Image and Body. I created a view for the above mentioned content type so that I would list view of all the categories I have created.
To custom theme the view I created a folder called views in my theme folder, and created the following view files:
views-view-fields--plugin-categories.tpl.php
views-view--plugin-categories.tpl.php
views-view-unformatted--plugin-categories.tpl.php
This is what I currently have in my first file:
<div class="<?php print $classes; ?>">
<?php if ($rows): ?>
<div class="view-content">
<?php print $rows; ?>
</div>
<?php elseif ($empty): ?>
<div class="view-empty">
<?php print $empty; ?>
</div>
<?php endif; ?>
<?php if ($more): ?>
<?php print $more; ?>
<?php endif; ?>
</div><?php /* class view */ ?>
Instead of $rows, I tired to use print $field['image'] and print $field['body'] but this method does seem to work. Could you kindly advise on how I could theme the three fields, within categories, displayed using view?
You should name your template like this
views-view-fields--<machine-name-of-your-view>.tpl.php
So I'm assuming from the above that your view is called 'plugin-categories'. An easy way to check is to go to edit the view and look at the URL while you're on the edit page. It should have the format /admin/structure/views/view/YOUR-VIEW'S-MACHINE-NAME/edit, so you can get it from there.
Once you're sure it has the right name, clear your cache to make sure Drupal is picking up your new template. You just need the one above, not all three to modify the output of the three fields in question.
Once you've cleared cache, Drupal should be picking up the new template. You didn't mention exactly what isn't working, just that it's not working, so I wanted to cover the naming and caching, just in case. Now, to output particular fields in this view template, call them like this:
$fields['your-field-machine-name']
So $fields['body'] (I think you're missing an 's')
You should have nothing about $rows in this template! If you have anything about $rows, you haven't copied and pasted from the correct views template. Simply output the fields as you want them to appear in your view, in whatever order you want with the syntax above and put in whatever css classes, etc you want.
Let us know if that works!

Joomla include view in other view

I have problem with including Joomla views. I have many views in my extension and I want to include another one in my Dialog.
How can I do it?
In my first view I have this code:
<div id="modalDostawca" title="Dostawcy">
<div id="wewM">
//in here i want to include view data/tmpl/default.php
</div>
</div>
What kind of extension is your extension? A module? A component?
If it's a component, what you are trying to include is a template for a view, not a view! (the view is the one with view.html.php). Create a view + template for what you are trying to see. I don't think Joomla! can call multiple views at the same time. If you can reuse code inside models (if this is your concern).
You can also include files the normal way, with include(...).

How do I separate the files for 'widgets' in codeigniter?

I have a basic cms that loads content into pages that have mustache tags to indicate where in the html code those contents will appear.
The contents are specified in a widget model which indicate which type of content is to be displayed, so for example, freetext with id. or another model and id. each one of those models will be displayed differently based on the model they are based on.
I can imagine this becoming and bit unwieldy, is there a way to have a separate folder to put those widgets in so that it doesn't clutter my main code.
Something like apotomo does on rails would be good, but for codeigniter.
A widget model? That is not so nice. Have you tried looking at PyroCMS?
https://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/modules/widgets/libraries/Widgets.php
From the sound of it you may be more interested in our Plugins library (sounds like the same thing with a different name). It is set up with a MY_Parser and runs on top of Dan Horrigan's Simpletags implementation.
Either way this has all be done plenty. If you want some more specific tailored advice you might have to demo some of your code.
Create a folder inside application/views called widgets. Put your widgets inside that folder and create a separate file for each widget (d0h).
Next, you have 2 options (at least that i know of):
a.) Load the widgets into variables inside the controller, then pass them to the main/general view
$data['widget_twitter_feed'] = $this->load->view('widgets/twitter', '', false);
$data['widget_something'] = $this->load->view('widgets/something', '', false);
$this->load->view('my_main_view', $data);
b.) Load the widgets inside the main/general view itself
<html>
...
<div id="sidebar">
<?php $this->load->view('widgets/twitter'); ?>
</div>
...
<div id="footer">
<?php $this->load->view('widgets/something'); ?>
</div>
...
</html>

Resources