For some reason, Laravel 4 won't update the content view that should be displayed in the browser.
For example, if I add one more item to the navigation menu, it is written on the view file, but not shown on the navigation list.
I have checked for any mispells, errors or anything related to this issue however I can't figure out if it's my mistake or it has to do with the cache.
What I've done:
Created the route for the url.
The related controller that will render the view.
Created the actual view with the content.
Added the item to the navigation file.
And I am sure that the view:
Extends with my layout
Included my content inside the #section and #stop'ed it.
And there are no errors displayed in the browser.
Also I've checked the storage folder which contains the view's cache, and I verified that the navigation file and the view file are phased correctly.
Looks like I need your advice guys.
Code as requested:
The route
Route::get('/account/profile', array(
'as' => 'account-profile',
'uses' => 'SettingsController#getProfileSettings'
));
Navigation
<li>Edit profile</li>
Controller
public function getProfileSettings() {
return View::make('account.profile');
}
View
#extends('layout.main')
#section('content')
Edit your profile...
Not yet...
#stop
First things I would do is:
Clear the view's cache folder.
check how you display the navigation, with #yield or #section, which should end with #show in the layout file.
If that didn't work maybe you could provide us with some code from the layout.
Related
I'm using custom error views with blade files located in resources/views/errors. My error views are made from the same template view than the normal pages so they extend my frontoffice layout. Here is the hierarchical scheme of my templates.
app.blade.php
layout.frontoffice.blade.php
someFrontOfficePage.blade.php
404.blade.php
The navbar component is included in layout.frontoffice.blade.php so I can't access it from 404.blade.php. Just to be clear, the navbar is a component as described here and is thus in yet another file.
The problem: I want to hide the links in the navbar but not the navbar itself when in an error view (such as 404.blade.php). The idea was to check if the status code is different from 200 inside my navbar component but I don't know how to access the response from a blade file.
I'd prefer to do it this way instead of copy-pasting my navbar inside a new error template to avoid redundancy.
well i had the same issue once, the solution is simple, in the error 404 blade you use extends('layouts.frontoffice') right ? then you can pass a variable to this extension, extends('layouts.frontoffice', ['code' => 404]) and in your navbar component :
#if(isset($code) && $code == 404)
//do something
#else
//do something else
#endif
I generated a project using, phalcon tools. In the config.php I changes view to:
'viewsDir' => APP_PATH . '/views/test/',
I have created two controllers: ExampleController and TestController
I have links pointing to http://example.com/test and http://example.com/test
In the views folder I have placed 2 files, one in views/test/example/example.phtml and another in views/test/test/test.phtml when I try to go to the links I get a blank page, if I move the phtml files in folder views/test/ the view that is loaded is the index.phml no matter which of the 2 url's I go to (this is the page that displays the 2 links above). If I echo out from the controllers this is displayed so the controllers are being accessed just the view are not being displayed. Please can someone advise? (Nb. If I use the default view configuration, then the views are being displayed)
You should place an index.phtml file in both directories. Thats the page that's loaded once you point to the respective controller. If you want it to load e.g example.phtml, you have to create an action called exampleAction in ExampleController. Then call it via http://example.com/example/example.
I'm building a navigation similar to wordpress basically what I want to do is add the navigation dynamically. my code in the header.blade.php looks something like:
#foreach($nav as $navs)
<li><a>$navs->title</a></li>
#endforeach
I will like the links to display in all my pages but I'm not sure how to set this in the route. Please any suggestion would be really helpful.
I'm still new to Laravel.
Sorry for not explaining properly, what I actually want is:
Once I add the navigation links and the details, it should display something like this
localhost/about-us
localhost/contact-us
So far I have got all the details and slug in the db.
e.g Controller to get all pages
class NavController extends Controller
{
public function nav()
{
$navs=Page::all();
return view('themes.first.header')->withNavs($navs);
}
}
e.g header.blade looks something like this
#foreach($navs as $nav)
<li>$nav->title</a></li>
#endforeach
The header is included on every page in master.blade so my issue is
for example I go localhost/blog
The links doesn't display but if I add route like this
Route::get('nav','NavController#nav');
Then go to /nav then it works fine. but I want something like this
localhost/about-us
and also for the links to display on every page. I hopefully I have explained properly now if not just let me know.
Please ignore suggesting code for the href="" because I've already done all that bit in my other pages etc so I know how to handle the code for the href, the part that I'm having issues is just with the navigation links not showing on all the pages.
Finally got the navigation working by using the suggestion from this thread
Proper way to make a dynamic navigation in Laravel 5
The blade syntax is wrong.
#foreach($nav as $navs)
<li><a>{{$navs->title}}</a></li>
#endforeach
Btw it's more likely that you wanted $navs as $nav and $nav->title.
If you have any problem with the routing part, share your code. Unless, I can only help with this.
In your route (example)
Route::get('page/{title}', 'PageController#details');
In PageController
public function details($title)
{
$page = Page::where('title', $title)->firstOrFail();
return view('your.page')->with(['page' => $page]);
}
In header.blade.php
#foreach($navs as $nav)
<li>{{ $nav->title }}</li>
#endforeach
How can I load views of my nav menu without reloading the entire main view? something like templates or partial views. Is necesary to do this with ajax? How can it be? I donĀ“t know much about ajax. It will be possible to see an example?
I load my home view in controller like this:
$data = [
'header_view' => 'main/header',
'nav_view' => 'main/nav',
'section_view' => 'main/main_view',
'article_view' => 'main/article',
'aside_view' => 'main/aside',
'footer_view' => 'main/footer',
];
$this->load->view('home_view', $data);
Then I load the vievs from home view:
<section>
<?=$this->load->view($section_view);?>
</section>
...
And in the nav view I wanted to put the links to different sections without reload the nav view, because I will have a tree structure and other stuff.
why don't you use AngularJS ? you can make a single page application using ui-routes or ng-routes. you can make ajax call to your controller method that will render your view, and you can show that view in .
EDIT
In order to do a one page iframe site, you need to set up a controller to return a page without anything else
Controller -> loadpage($name)
then route it however you'd like
then, create an iframe with an id
<iframe name="maincontent"></iframe>
obviously, add in your needed styling / attributes.
On your links, add in targets
Link 1
I have a create form which is loaded using renderPartial (standard after using the yii crud tool):
<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>
I removed the code which renders the sidebar menu, and the menu doesn't show anymore. But still there's some generated code left when I look into browser my source code:
<div class="span-5 last">
<div id="sidebar">
</div><!-- sidebar -->
</div>
This messes up my layout and I can't find where I can remove this last part. Does someone know where this happens?
There are two things to consider here, do you want this removed over the whole site (i'll explain all methods). If so go to the following directory
/protected/views/layouts
Then edit the column2 layout, which is likely the default layout being used and remove the sidebar code. Now all pages should no longer have the sidebar.
If you want to remove this either on all actions of a controller or for a specific controller action, do the following. Duplicate colum2.php and call it say nosidebar.php. Then in the nosidebar.php file, remove the sidebar code.
To change all actions in a controller specifiy the layout like so.
class AccountsController extends Controller
{
public $layout='//layouts/nosidebar';
or to change a specific action add this inside the action method
$this->layout='nosidebar';