Laravel 4 View Nesting Main Layout Subviews Content and Sidebar - laravel-4

This is my first post so please be gentle with me.
I have set my master layout to call "main"
<div class="row">
{{$main}}
</div>
and I have a view called home.blade
<div class="col-md-9">
<div class="content">
{{$content}}
</div>
</div>
<div class="col-md-3">
<aside class="sidebar">
{{$sidebar}}
</aside>
</div>
and in my controller I have:-
$this->layout->main = View::make('home')->nest('content', 'property.viewmany', compact('properties'));
This works for the content variable, but at this point I'm stumped at how to get the sidebar variable to work. Is there a way to nest the two variables into the home.blade from the controller?
I've attempt various, albeit, shots in the dark, but I always get either content not defined or sidebar not defined.

You can put a first variable in the first view like this:
$this->layout->main = View::make('home', compact('sidebar'))->nest('content', 'property.viewmany', compact('properties'));

Related

Laravel PHP If/Else in Blade Doesn't Work

Laravel PHP fans, Any idea why this renders both the actual partial view and the No Data Found as well? And interestingly, it renders No Data Found first. If I do a dump and die in the if condition, I get that dd. If I put it in the else condition, I get it there. It must be that the page starts rendering before the data for regionLevel actually comes back. Then when it does it dutifully prints it out. Is there any way around this weirdness?
#if(isset($regionLevel) && count($regionLevel) > 0)
<div class="size-wrapper">
#include('manager/reports/order-data/sections/partials/region-partial')
</div>
#else
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-left m-t-5 m-b-5 m-l-10">No data found.</div>
</div>
</div>
#endif

Pagination is not showing

I'm trying to get pagination into my view. I don't know where is the problem, the code doesn't show any errors.
Here is my controller function
public function apakskategorijas($id)
{
$apakskat = apakskategorijas::with('prece')->where('id',$id)->paginate(2);
return view ('kategorijas.apakskategorijas',compact('apakskat'));
}
View
#section('content')
#foreach($apakskat as $apk)
#foreach($apk->prece as $prec)
<div class="col-md-4 kat">
<a href="{{ url('kategorija/apakskategorija/preces/'.$prec->id) }}">
<div>
<img src="{{ URL::to($prec->path) }}">
</div>
<div class="nos">
<p>{{$prec->nosaukums}}</p>
</div></a>
<div class="price-box-new discount">
<div class="label">Cena</div>
<div class="price">{{ $prec->cena }} €</div>
</div>
<div><span>Ielikt grozā</span></div>
</div>
#endforeach
#endforeach
<center>{{$apakskat->links()}}</center> <--pagination
#endsection
dd($apakskat)
UPDATE
when i changed code in my controller to $apakskat = apakskategorijas::paginate(1); then it showed me pagination, but this doesn't work for me since i need to display items in each subcategory, with this code it just displays every item i have,it doesn't filter which subcategory is selected.
This is why i need this $apakskat = apakskategorijas::with('prece')->where('id',$id)->paginate(1); with is a function that i call which creates a relation between tables, so that it would display every item with its related subcategory.
That's the behavior of paginator in current Laravel version. When you have just one page, pagination links are not displayed.
To test this, just change the code to something like this to get more pages:
$apakskat = apakskategorijas::paginate(1);
If you want to show the first page if there is only one page, you need to customize pagination views. Just publish pagination views and remove this #if/#endif pair from the default.blade.php but keep the rest of the code as is:
#if ($paginator->hasPages())
....
#endif

WebAPI Knockout JS Image Binding

I am using Knockoutjs to render a user profile page. For which I am calling a Web API service which returns User details with its Profile Picture.
var MessageFrom = {
FromUserProfileId: self.FromUserProfileId,
FromUserName: self.FromUserName,
FromUserPictURL: self.FromUserPictURL
}
<div id="comments" class="comments" data-bind="with: viewModel">
<div class="comment clearfix" data-bind="foreach: Messages">
<div class="comment-avatar">
<img class="img-circle" data-bind="attr:{'src': FromUserPictURL}" alt="avatar">
</div>
<header>
<h3 data-bind="text: FromUserName"></h3>
<div class="comment-meta"><p data-bind="text: moment(DatePosted).format('LLL')"></p> </div>
</header>
<div class="comment-content">
<div class="comment-body clearfix">
<p data-bind="text: MessageBody"></p>
</div>
</div>
</div>
</div>
The URL of the Image returned from WebAPI is Relative URL like ~/Content/Member/Image1.jpg. While its bind with Image URL shows like "http://sitename.com/profile/~/Content/Member/Image1.jpg".
Everything works great accept Profile Picture
I need to work something on binding as as I cannot change the Path coming from Database.
Appreciate your suggestions.
Regards,
Your binding looks okay. For starters I would use your IE or Chrome developer tools ( F12 ) and change the src manually of the image to find out what exactly works for you.
You say you recieve this: ~/Content/Member/Image1.jpg
Setting the src to this should work: /Content/Member/Image1.jpg
You can change your message object client-side like this, once you're sure what is needed, but I think this should suffice:
var MessageFrom = {
FromUserProfileId: self.FromUserProfileId,
FromUserName: self.FromUserName,
FromUserPictURL: self.FromUserPictURL.replace('~','')
}

EmberJs: nested views

I have this view which can rotate a div element. Something like
<div class="rotatable">
<div class="front">
{{outlet front}}
</div>
<div class="back">
{{outlet back}}
<div>
</div>
Now I have this index template which contains two of these rotatable elements. Each rotatable elements has a different front and back. So it could look like this
<div id="index">
{{#rotatable}}
{{outlet front App.FrontView1}}
{{outlet back App.BackView1}}
{{/rotatable}}
{{#rotatable}}
<div>This should show up inside {{outlet front}}</div>
{{outlet back App.BackView2}}
{{/rotatable}}
</div>
This doesn't work of course, but how should this be done ?
Cheers
I guess this question was a little bit unclear. Anyway, the answer is given in this post
EmberJs: how to use connectOutlet

ViewBag does not show messege in view

I created 2 div's inside a view.
to display content inside that i have used partial view and to show errors i am using Viewbag and displayed it as follows:
<div id="tabs">
<ul>
<li>Publish Exhibition</li>
<li>Edit Existing Exhibition</li>
</ul>
<div id="tabs-1" style=" width:900px; height:400px;">
<font color="red">#ViewBag.msg1</font>
#{Html.RenderPartial("PubExhi", Model);}
</div>
<div id="tabs-2">
#{Html.RenderPartial("EditExhi");}
</div>
</div>
I'm calling this view as
ViewBag.msg1 = "record not updated!!!!";
modelList = setIndex();
return View("Index", modelList);
evry thing is working fine except the viewbag
it is not displaying any msgs
When i debugged it, i can see the viewbag containing appropriate value
but it is not displaying on the page
I also tried to display it from the partial view but not getting any message
Can any body help me
Use #Html.Raw(ViewBag.msg1) to display.....
It should work, i tried exactly similar thing and it is working for me -
<div id="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
</ul>
<div id="HWTab">
<font color="red">#ViewBag.msg</font>
#{Html.RenderPartial("_HardwareAssetView", Model.hardwareAssetVM);}
</div>
<div id="AdminTab">
#{Html.RenderPartial("_AdminAssetView", Model.adminAssetVM);}
</div>
you need to assign it to the view you are sending in your server method: let's say my viewresult is Details, but you are sending view DetailingList, then you need to assign this view's viewbag the message you want:
var partialViewRes = new PartialViewResult();
partialViewRes.ViewName = "DetailingList";
partialViewRes.ViewData.Model = list;
partialViewRes.ViewBag.ErrorMessage = "Error on loading";
Hope this helps someone.

Resources