The default way to add a menu to a template::
{{ menu(identifier = 'footer',
template = 'partials/_sub_menu.twig',
params = {'withsubmenus': false, 'class': 'inline-list align-right'}**strong text**
) }}
But how to build a secondary menu from other files than menu.yml?
To add a secondary menu go to menu.yml add for the mentioned example this lines of code:
footer:
- label: Imprint
title: Go to Imprint
path: page/imprint
class: first
The documentation can be found here: https://docs.bolt.cm/3.0/content/menus
Further explanation:
All menus used have to be declared in menu.yml.
To render them correctly you can call them in two different ways.
Example #1:
{{ menu(identifier = 'footer', template = 'partials/_sub_menu.twig') }}
Example #2 (Short hand syntax):
{{ menu(footer', 'partials/_sub_menu.twig') }}
Note: You can define more than one menu in your menu.yml file, but you
should define only one menu in each template file. So, if you have
multiple menus that should be rendered with different HTML, you should
have as many _menu_menuname.twig files in your theme.
Related
Is it possible to use custom page variable in Configuration section in OctoberCMS?
When I do this:
url = "/blog"
layout = "default"
custom_var = "value"
==
{{ custom_var }}
my custom_var is deleting when edit page from admin panel.
It seems this was the old way of defining all stuff in single view (visual representation)
now its divided in 3 portion
1st name and url(slug) then 2nd markup(html) section
3rd code section
so you can follow new way of declaring things and it should work
use code section add this
public function onStart() {
$this['custom_var'] = 'some value';
}
use markup section and add this
<h1>{{ custom_var }}</h1>
it will work, still any issue please comment.
Yes, its possible to set custom variable into page. you can try the following code into the php section
function onEnd() {
$this->page->custom_var = 'some data';
}
And then you can use this custom_var into your layout file like
{{ this.page.custom_var }}
If you want to define new variables inside markup you can use following syntax:
{% set custom_var = 'some data' %}
I'm not that experienced with Laravel, so I have created a project for myself to learn the Laravel framework better. I have started with a free HTML template and tried to turn that into a Blade template. I have the following:
app.blade.php
This contains the basic HTML structure and the JS en CSS. Besides that, it contains the following code:
<main class="page-content content-wrap">
#include('layouts.topbar')
#include('layouts.menu')
#yield('content')
</main><!-- Page Content -->
topbar.blade.php
This contains the simple topbar that the template included, not that interesting for this question.
menu.blade.php
This contains all of the menu items I have. This file contains the whole menu-div and all of the menu items with ul and li. In this file, I can give a ul & li the class "active", so it shows that you're on page X. The standard ul (not active) is the class "droplink", when it's active, it's called "droplink active open".
Views for the website itself
In the views for the website I include the app.blade.php and I fill the content section in the view. Now my question is, how can I change that the correct page is showing active in the menu? My feeling says I can't define that in the menu.blade.php, but where can I?
You can check current route in menu.blade.php
If it matches with the current route than you can add active class.
<a class="{{ str_contains(request()->url(), '/some-page') ? 'active' : '' }}" href="/some-page">Some Page</a>
Name your routes ->name('homepage');
And in your menu you can use this for exmaple:
<li class="{{ isActiveRoute('dashboard') }}">
Which will return 'active if its active'
Use css to customize your active class
Edit
Add the helper function in app/Helpers/Navigation.php
function isActiveRoute($route, $output = 'active')
{
if (Route::currentRouteName() == $route) {
return $output;
}
}
And in order to use it everywhere register it in your AppServiceProvider.php
public function register()
{
require_once __DIR__ . '/../Http/Helpers/Navigation.php';
}
You can do it like this
#if(Route::getCurrentRoute()->uri() == '/') <li class="active"></li> #endif
It can be also used like this for example
<li class="#if(Route::getCurrentRoute()->uri() == '/')active #endif"></li>
For other routes to check just change the / to something like about-us or whatever you need.
This whill check for the current route. If the current route is / or root in this case it will add the li with class active. You can place this wherever you need it.
You can use this approach for each of your routes in 'layouts.menu'
I have a twig template of navigation and footer with links to main page.
{{ url("help") }} -> https://main.com/help
I am rendering them on subdomain from same codebase. But I do not want to have links to subdomain page.
{{ url("help") }} -> https://subdomain.com/help //but I need https://main.com/help
How can I set domain for template or what is the optimal solution, other then duplicating templates and setting urls directly?
I've got the section in my master template
#section('errors')
// ...
#stop
I wanna yield it in some specific place of my other page, I extended that page from master template and yielding the section
#extends('template')
#yield('errors')
But nothing is yielded. I assume that I am just doing this wrong. Is there the right way?
Normally you put in master template:
#yield('errors')
and in child template you use:
#section('errors')
// ...
#stop
to display something in place when in master template you used #yield('errors')
But in your case if this section appears on many pages you can use in parent template:
#yield('errors')
and in child template:
#section('errors')
#include ('errors')
#stop
and create new errors.blade.php file that displays error.
Of course everything depends on your needs. You can of course also in parent template use:
#include ('errors')
instead of yielding.
I ma trying to use Laravel Pagination and I only want to show the Previous and Next link with out the number 1 2 3 ...
how could I do that? I followed Laravel page :
"Simple Pagination"
If you are only showing "Next" and "Previous" links in your pagination view, you have the option of using the simplePaginate method to perform a more efficient query. This is useful for larger datasets when you do not require the display of exact page numbers on your view:
$someUsers = User::where('votes', '>', 100)->simplePaginate(15);
but this still shows the page number when I do this in my view:
<?php echo $someUsers->links(); ?>
can anyone help
Thanks
tldr; you want to use simplePaginate() method on the query AND links('some.view') on the paginator (in the view) in order to achieve what you ask for.
Here's what you need in order to show chosen links in given template:
// inline choose simple links (prev, next)
{{ $someUsers->links('pagination::simple') }}
// inline choose slider links
{{ $someUsers->links('pagination::slider') }}
// inline choose slider-3 (default)
{{ $someUsers->links('pagination::slider-3') }}
These are framework's templates, placed in laravels directory: Illuminate/Pagination/views/
You can always decide to use your custom templates, for this simply call:
// assuming you have it in app/views/pagination/my-links.blade.php
{{ $someUsers->links('pagination.my-links') }}
// or using views namespace (you need to define it first)
{{ $someUsers->links('myNamespace::my-links') }}
Of course you can define your links as default in app/config/view.php:
// instead of
'pagination' => 'pagination::slider-3',
// something like
'pagination' => 'pagination.my-links',
You need to use:
$someUsers = User::where('votes', '>', 100)->simplePaginate(15);
as you used
and in app/config/view.php you need to set pagination to pagination::simple (by default it's set to pagination::slider-3). Then you'll have by default pagination as in the image:
You can also set custom text for previous and next items editing file lang/en/pagination.php (for other language of course you need to change it in other lang directory). By default it's set to:
'previous' => '« Previous',
'next' => 'Next »',
but you can change it to:
'previous' => '«',
'next' => '»',
and then it will look like as in the image:
I tried this and it's working with me :
{{$someUsers->links('pagination::bootstrap-4')}}
In config/view.php:
/*
|--------------------------------------------------------------------------
| Pagination View
|--------------------------------------------------------------------------
|
| This view will be used to render the pagination link output, and can
| be easily customized here to show any view you like. A clean view
| compatible with Twitter's Bootstrap is given to you by default.
|
*/
'pagination' => 'pagination::slider-3',
Set this to simple.
Source: http://youtu.be/lIEcyOUcNQk?t=8m00s
See the very bottom of this manual page to see how to implement a custom view for the pagination. Summarizing, you need to follow these steps:
Create a view for the paginator somewhere in app/views.
Replace the pagination option in app/config/views.php with the path Laravel will use to locate your new view.
Display your custom paginatation view in your view like this:
<?php echo with(new ZurbPresenter($paginator))->render(); ?>
Where ZurbPresenter is the class name of your pagination presenter.