Dynamic nav laravel 5.3 - php

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

Related

Laravel: problems with rendering sections (->renderSections) and content section

it seems quite simple. i have a controller, a class/object and a view for it (show/edit). and i want to render this view in an overview/listing.therefore i have to extract the the 'content' section.
demo.blade.php
#extends('mainlayout.main')
#section('content')
Content of the object
#endsection
so i use in the overview template (overview.blade.php) the following code
$sections = View::make('demo')->renderSections();
echo($sections['content']);
what happens? the content here overwrites everything in the section (content) of the overview.blade.php
i also tried to take another name for the section like 'contentnew' and than ! it works.
so my questions?
should it work with section 'content'? or do i understand something wrong with the template engine?
why is 'content' handled different than contentnew. simple because it is not parse?
thanks for any help.
t00cg

Export a list of users in OctoberCMS to CSV

I have read tutorial about using the import and export functionality in OctoberCMS.
But with the rainlab-users plugin, these guidelines don't work. I also tried to install the plugin vojtasvoboda-userimportexport, but it exports all users, not filtered ones.
class Users extends \RainLab\User\Controllers\Users
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.Behaviors.ImportExportController',
];
....
}
When I added this code into Users.php controller, I got an error:
Class .....\User\Controllers\Users has already been extended with Backend\Behaviors\ImportExportController.
When I try export without code above, I got error:
Call to undefined method October\Rain\Database\QueryBuilder::export()
I think its little difficult as we are not having access to user plugin toolbar to add button so.
But YES we can do it, we need to try little harder :) lets start
End result
To add export button we need to Extend rainlab.user plugin. So from your own plugin you need to it.
1. Adding Extension code to your plugin's Boot method
class Plugin extends PluginBase
{
use \System\Traits\ConfigMaker; // trait to read config
public function boot() {
\RainLab\Users\Controllers\Users::extend(function($controller) {
// we only extend if its not already extended with ImportExport Behavior
if(!$controller->isClassExtendedWith('Backend.Behaviors.ImportExportController')) {
$controller->implement[] = 'Backend.Behaviors.ImportExportController';
// make sure you replace this path to your plugin directory
$extensionPath = '$/hardiksatasiya/stackdemo/user_extension_files/';
$controller->addDynamicProperty(
'importExportConfig',
$extensionPath . 'config_import_export.yaml'
);
$newListConfig = $this->makeConfig(
'$/rainlab/user/controllers/users/config_list.yaml'
);
$newListConfig->toolbar['buttons'] =
$extensionPath . '_new_list_toolbar.htm';
$controller->listConfig = $newListConfig;
}
});
}
....
2. Creating folder and files
Create folder inside your plugin's root directory and name it user_extension_files
Inside that directory
Add config_import_export.yaml with content
export:
useList: true
Add _new_list_toolbar.htm with content [ It will be just copy of plugins/rainlab/user/controllers/users/_list_toolbar.htm with slight modification]
With adding Our Brand New Shiny Export button not pasting whole code it will be too long so just pasting fragment of it.
<div data-control="toolbar">
... copied code ...
<!-- our export button -->
<a
href="<?= Backend::url('rainlab/user/users/export') ?>"
class="btn btn-primary oc-icon-sign-out">
Export
</a>
</div>
Now, when you click on export button it should export records and It will also
respect all the applied filters.
#NOTE: we are copying code to _new_list_toolbar.htm, So in future if user plugin is getting updated and they decide to add new buttons in tool-bar then we are not able to have that changes. So in that time we just need to copy & paste code from plugins/rainlab/user/controllers/users/_list_toolbar.htm to our file _new_list_toolbar.htm again. We are back in business again :) .
if any doubts please comment.
So I actually solved something like this in a different way than in the controller. I make make a decoupled front end admin system. So website owners never have to log into the backend. Which trust me has saved numerous headaches and mistakes by users that mess with things they shouldn't. So here is how I have solved this:
Install plugin Content Type by Sozonov Alexey
Make a CMS Page and make sure it has .csv at the end of the url. You
should see that the content type plugin added a content type tab in
the page settings. You can leave the html selection alone but add
text/csv as your own to the right of it.
Here is an example on how the template of the page looks like.
{% spaceless %}
NAME,EMAIL
{% for row in csv %}
{{ row.name }},{{ row.email }}
{% endfor %}
{% endspaceless %}
Here is how the CMS Page PHP Code section would look. This can allow you to do queries on the list and filter as desired. You could then check to see if the client is logged into the backend or is logged in as a user and maybe is an admin or moderator. Of course you can make a plugin and component then attach it to this page.
use Rainlab\User\Models\User;
function onStart() {
$users = User::all();
$this['csv'] = $users;
}
Side note I have used this same technique to create dynamic css, javascript, or rss feeds. I make the site map using this as well.

Laravel 4 Won't update views content

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.

Can't find Joomla pagination template

I'm going crazy with this one. I am trying to change a little bit the pagination style and layout in Joomla. So, I found this file: libraries\joomla\html\pagination.php but I know that pagination is overridden by this file: templates\gk_yourshop\html\pagination.php. Yet, if I modify something in gk_yourshop\html\pagination.php, I can't see the change in the pages. Does joomla cache templates and I have to re-load them (like phpBB)?. I don't understand.
I tried to check if writePagesLinks is called from joomla\html\pagination.php with this:
function getPagesLinks()
{
echo "test";
global $mainframe;
and I can't see the message. I also did this in the other pagination.php file and it's just like I can delete them and it doesn't matter. Can you help me? Thanks!
Looks like I changed it here some time ago:
\libraries\joomla\html\pagination.php
But, that is system file, so i just make a "hotfix" of it.
In Joomla 3.x you can create pagination override from Extensions > Templates > Default Template > Create Overrides > Layouts > Pagination.
The override files are created in "Default Template" "html\layouts\joomla\pagination" folder.
You can edit the override files as per your needs.
Where are you getting WritePageLinks from? That's not one of the supported methods.
http://docs.joomla.org/Understanding_Output_Overrides#Pagination_Links_Overrides
There are four functions that can be used:
pagination_list_footer
This function is responsible for showing the select list for the
number of items to display per page.
pagination_list_render
This function is responsible for showing the list of page number links
as well at the Start, End, Previous and Next links.
pagination_item_active
This function displays the links to other page numbers other than the
"current" page.
pagination_item_inactive
This function displays the current page number, usually not
hyperlinked.
[edit]
You may also want to look at Protostar as an example.

wordpress plugin admin menu

I am trying to create a wordpress plugin admin menu. The problem that I am running into is with the menus. I am trying to add a page in the admin without actually adding the menu link. So for example I want to have a menu called test then I want to have some extra pages but I don't want physical links to them because they are only going to be used when there is an id to pass to them. is this possible and if so please someone explain because i can't seem to figure it out.
Yes. In your callback function for the admin page, just write out different sections and use conditional checks to display the right content. Then, under the page's title, add a <ul> with the class subsubsub containing the links to take the user to the right place. Something like this:
function my_awesome_admin_page(){
echo '<h2>My Title</h2>';
echo '<ul class="subsubsub"> <li>Foo</li> <li>Bar</li> </ul>';
if($_GET['foo'] != 'bar'){
//You're on the first page
} else {
//You're on the second page
}
}
I forget what the class is to signify the current subpage, but you can take a look on the 'Add Plugin' admin page. I think it's selected.

Categories