I can not find a solution how to include blade template using button click.
For example lets say I have a main view:
<div id="HEREGOESMYTEMPLATES">
</div>
<div class="row">
<button onclick="addTemplate()">ADD TEMPLATE</button>
</div>
Then script, which should include template
<script type="app/js">
function addTemplate()
{
//Get template and include into div with id HEREGOESMYTEMPLATE
}
</script>
And then the template itself (lets say partial.blade.php):
<div>Include me to main blade file</div>
Is there any possible way by including it without creating every tag in JS and then appending to the div?
Thank you.
UPDATE.
As blade template is not supposed to do such work as it is rendered in backend, I used VueJS to this, which I believe is the best solution in this situation.
Let's say i have three blade templates: A, B and C. Template A is the global layout, template B is some specific section's layout and template C is the view template.
Templates A and B expect a section called content to be assigned. That section is defined in the view templates (C).
Here's a simplified version of templates A and B:
Template A:
<html>
<body>
#yield('content')
</body>
</html>
Template B:
#extends('template_a')
#section('content')
<div class="sidebar">
...
</div>
<div class="content">
#yield('content')
</div>
#endsection('content')
As you can see, both templates output a content section. My problem is that in views that extend B it's content is simply ignored. The content section defined in the view is output on the #yield('content') present at template A.
I would like to know if it is possible to propagate the content section up in the view hierarchy, i.e., replacing the the content placeholder in template B with the value defined in template C and replace the result in content placeholder in template A.
Sorry if i made this sound too confusing. I hope you get my idea.
Thanks in advance.
I found an answer to your problem here: https://laracasts.com/discuss/channels/laravel/trouble-with-blade-section-inheritance?page=1
The trick is to use #overwrite instead of #endsection in the blades that contain a #yield inside a #section with the same name.
#extends('app')
#section('content')
{{--Some common code--}}
#yield('content')
#overwrite
Using #endsection causes yielded views to override the intermediate view, but using #overwrite forces inclusion along the way.
The confusing thing, in my opinion, is that in conventional programming the directive to make use of the superclass method goes in the subclass (calling the superclass method from the subclass) whereas in Laravel blade inheritance it must be placed in the superclass itself (the superclass declares within itself that it cannot be ignored when overridden).
Just rename the #yield('content') in Template B. A #endsection (Laravel5) is enough to end those sections.
Template A:
<html>
<body>
#yield('body')
</body>
</html>
Template B:
#section('body')
<div class="sidebar">
...
</div>
<div class="content">
#yield('content')
</div>
#endsection
Template C:
#section('content')
<!--yourContent-->
#endsection
This way you can easily change your Template B with any other given Template to modify the body (i.e. Template D):
#section('body')
<!-- Some different Body Style -->
#yield('content')
#endsection
as well as your content (i.e. Template E):
#section('content')
<!--some different Content-->
#endsection
Edit:
Probably the reason for Template B not showing any data from Template C is an infinite Loop caused by Template B: Every time you call the section('content') you also yield('content') and inserting Template B into itself.
I'm using Laravel 5 with angularjs Trying to loop through jsonp reply showing World of Warcraft wowhead_tooltips and have come to a problem I cannot decipher. Snippets included below.
wowhead script retrieves the item name and displays a tootip template for wow items. ng-repeat prevents the item name to be displayed, if I insert #{{topic.itemId}} the item number is displayed and the tooltip works wihtout the item name.
The exact html block with an actual item number outside ng-repeat
works fine. So the problem is 100% to do with ng-repeat, how can I get
around this ?
Laravel blade file Tooltip works outside of ng-repeat fails inside.
<SECTION id="feeds" ng-app>
<!-- Test outside loop Works Fine -->
<!-- Works ! -->
<div ng-controller="FeedsController">
<p>Guild Achievements: <b>#{{ guild_feed.achievementPoints }}</b></p> <!-- Works ! -->
<div ng-repeat="topic in news">
<div ng-switch="topic.type">
<div ng-switch-when="itemCraft">
#{{topic.character}} Crafted:
<!-- Displays nothing, however if I place #{{topic.itemId}} enclosed in a tag only the item number displays and the tootip works, uunlike above though no item name is displayed from WoWhead. -->
<hr/>
</div>
<div ng-switch-when="itemLoot">
{{--#{{topic.character}} Looted: #{{topic.itemId}}--}}
<p></p>
<hr/>
</div>
... Rest of code
Typical wowhead script (Works fine)
<!-- Wowhead Tooltip Scripts -->
<script type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script>
<script>
var wowhead_tooltips = {
"colorlinks": true,
"iconizelinks": true,
"renamelinks": true
}
</script>
My Angular js file to rereive list (Works fine)
function FeedsController($scope, $http) {
$http.jsonp("https://us.api.battle.net/wow/guild/dreadmaul/sons%20of%20anarchy?fields=news&locale=en_US&jsonp=JSON_CALLBACK&apikey=MYKEY").
success(function(data) {
$scope.guild_feed = data;
$scope.news = data.news;
});
}
From the Laravel docs, you can include 'sections' inside layouts using two methods:
<html>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
</html>
Since #yield can also pass in some default content using #yield('section', 'Default Content'), is #yield just a shorthand for a #section that does not use #parent?
#section
<!-- Nothing here -->
#show
What other differences are there?
Short Answer: Always use #yield unless you want to do something more complicated then providing a default string.
Long Answer:
Both #yield and #section .. #show are used to be optionally overwritten whenever you extend the blade template. Everything you can do with #yield can also be done with #section .. #show but not the other way around. Here is what they do:
#yield('main')
Can be replaced by #section('main') .. #endsection
Can be provided with a default string but no HTML! The default string will be shown in the sub-blade-template when no #section('main') .. #endsection is provided.
#section('main') .. #show
Can be replaced by #section('main') .. #endsection
Can be provided with a default HTML code. The default HTML code will be shown in the sub-blade-template when no #section('main') is provided.
Can be replaced by #section('main')#parent .. #endsection and additionally shows the default HTML code.
Here some examples:test.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<h1>This is a test</h1>
#yield('mainA')
#yield('mainB', 'This is the alternative 1')
#yield('mainC', '<p>This is the alternative 2</p>')
#yield('mainD', 'This is the alternative 3')
#section('testA')
#show
#section('testB')
This is the alternative 4
#show
#section('testC')
<p>This is the alternative 5</p>
#show
#section('testD')
<p>This is the alternative 6</p>
#show
</body>
</html>
here is another file called testA.blade.php which extends the other bladed file:
#extends('test')
#section('mainD')
<div>
<p>First replacement!</p>
<hr>
</div>
#endsection
#section('testC')
<div>
<p>Second replacement!</p>
<hr>
</div>
#endsection
#section('testD')
#parent
<div>
<p>Additional content</p>
<hr>
</div>
#endsection
And that is the outcome:
This line clears out the confusion: "Note that views which extend a Blade layout simply override sections from the layout. Content of the layout can be included in a child view using the #parent directive in a section".
So, if you already have a #section defined in the master layout, it will be overriden unless you specify #parent inside the child layout's #section.
But for #yield, it always gets the section from the child layout. That means it always overrides the #yield part, even if it has a default defined as #yield('section', 'Default Content') .
I hope that clears your confusion. Let me know if you have more questions. Thanks
The shortest answer:
Use #yield in master if you want to overwrite child data on master layout completely.
Use #section in master if you want to use master and child data together on child with #parent (Or overwrite child data on master layout like #yield)
Basically yield('content') is a marker. For example, in the tag if you put a yield('content'), your saying this section has the name of content and by the way, you can name inside of the parenthesis anything you want. it doesn't have to be content. it can be yield('inside'). or anything you want.
And then in the child page where you want to import html from your layout page, you just say section('name of the section').
for example, if you have marked your header in your layout page as yield('my_head_band') <-- or anything else you want, then in your child page you just say #section('my_head_band').
This would import the header from the layout page into your child page. vice versa with your body section which in this case was named as content.
Hope this helps.
Just to add on something small, #yield basically defines a section to be injected by overwriting the data and it also works if our view #extends the parent view.
Now when we overwrite, we replace an implementation completely with a new implementation, like a company can decide to change/overwrite its entire technology if they realize something went wrong.
It should not be confused with override
#yield having default value in second parameter and section doesn't have in master if you want to overwrite child data on master layout completely then you will use #yield.
Use #section in master if you want to use master and child data together on child with #parent (Or overwrite child data on master layout like #yield)
Example
<html>
<head>
<title>App Name - #yield('title')</title>
</head>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
</html>
#extends('layouts.master')
#section('title', 'Page Title')
#section('sidebar')
##parent
<p>This is appended to the master sidebar.</p>
#stop
#section('content')
<p>This is my body content.</p>
#stop
first of all i have a phtml page like this :
<div>
...
</div>
<form>
...
</form>
what i wanna do is display this phtml just like this shema and not inside html and body nodes
is there any possibility to do this ?