Volt adding multiple class in view - voltrb

I'm building a website with Volt 0.9 and I'm trying to customize my main.html regarding navigation.
Well, there is and if binding in the :Nav section to add a class. The problem is that I want to add another class with another if binding. I've tried to add a second if binding, but no luck, the are not rendered when I'm using a second if binding.
How can I do that ?
Here's the file :
<:Title>
{{ view main_path, "title", {controller_group: 'main'} }}
<:Body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<ul class="nav navbar-nav pull-left">
<:nav href="/">Hammicus</:nav>
<:nav href="/tv">HammicusTV</:nav>
<:nav href="/radio">HammicusRadio</:nav>
<:nav href="/contact">Contact</:nav>
</ul>
<:volt:notices />
{{ view main_path, 'body', {controller_group: 'main'} }}
</div>
</nav>
<footer class="footer">
<p>© Hammicus {{ Time.now.year }}</p>
</footer>
<:Nav>
<li class="{{ if active_tab? }}active{{ end }} {{ if attrs.href == "/" }}brand{{ end }}">
{{ yield }}
</li>

The problem seems to be the double quotes around the "/"
Replace them with single quotes (so they are properly nested) and it should work.
ie
class="{{ if active_tab? }}active{{ end }} {{ if attrs.href == '/' }}brand{{ end }}"

Related

After Click Add to Cart Button then Button Change to Go to Cart in Laravel 8

Please help me, i'm right now try to change Add to Cart Button to Go to Cart after click, how possible I can do that?, please help me, I have trying but didn't work, here my condition code in Controller:
if (Temporary::where('course_id','=', $request->IDCourse)->exists()) {
Session::flash('failed-session','Go to card');
}
else
{
Session::flash('failed-session','Add to cart');
}
and below my blade for looping product on cart box
#foreach($carts as $cart)
<ul class="list-group list-group-flush">
<li class="list-group-item bg-light">
<div class="row">
<div class="col">
<input type="text" name="IDCourse" value="{{ $cart->course_id }}">
<a href="{{ route('course.detail', $cart->course->id) }}" class="text-body">
<div class="d-flex">
#if($cart->course->image == '')
<img src="{{ asset('storage/courses/Default_Photo.png') }}" alt="" class="avatar-md square" />
#else
<img src="{{ asset('storage/courses/'.$cart->course->image) }}" alt="" class="avatar-md square" />
#endif
<div class="ms-3">
<h5 class="fw-bold mb-1">
{{ $cart->course->title }}
</h5>
<span class="fs-6 text-muted">
<span>{{ __('Oleh ') }}{{ $cart->course->user->name }}</span>
</span>
</div>
</div>
</a>
</div>
</div>
</li>
</ul>
<hr class="my-0">
#endforeach
And the last code to display the result from condition in controller
#if(Session::has('failed-session'))
<div class="alert alert-danger">
{{Session::get('failed-session')}}
</div>
#endif
I try dd($request->course_id) and displaying null. My planning is to check if customer have add to cart that item then the button change to Go to Cart. Please help me.Thank u so much for any help.
simply just check this item in your controller then initialize the variable and check if variable is empty or not , then you can change the action of the form or change the src of the button ,
for example : if user->cart->count() > 0
redirect to the page
you can add another button for continue shopping as well too .

Laravel 7.x with Nova Can't use menu from optimistdigital/nova-menu-builder

I am new to Laravel Nova ... I just installed optimistdigital/nova-menu-builder in order to generate menus in a more efficient way then whats generated by nova. My menu structure is very complex and needs more control. Anyway, I installed the package and created a menu. I am at the point where I would like to load it in the sidebar but can't figure out how that works ...
in the navigation.blade.php file I added:
#menu("admin")
Where admin is supposed to be the menu slug
After a refresh, nothing happened. So I tried something more basic. I removed the #menu and added "hello world" instead. It did not appear ... So I ran the following commands:
php artisan config:clear
php artisan cache:clear
php artisan nova:publish
All 3 were executed without any errors. But the sidebar still did not show my hello world.
So my question is the following. How can I reflect my changes in the blade views? And is #menu("") the right way to use the optimistdigital/nova-menu-builder package? The documentation seems to be missing the part on how to use the menus you create... Thx in advance!
Here's my layout page
<router-link exact tag="h3"
:to="{
name: 'dashboard.custom',
params: {
name: 'main'
}
}"
class="cursor-pointer flex items-center font-normal dim text-white mb-8 text-base no-underline">
<svg>[Long SVG string]</svg>
<span class="text-white sidebar-label">{{ __('Dashboard') }}</span>
</router-link>
hello world
#menu("admin")
#if (\Laravel\Nova\Nova::availableDashboards(request()))
<ul class="list-reset mb-8">
#foreach (\Laravel\Nova\Nova::availableDashboards(request()) as $dashboard)
<li class="leading-wide mb-4 ml-8 text-sm">
<router-link :to='{
name: "dashboard.custom",
params: {
name: "{{ $dashboard::uriKey() }}",
},
query: #json($dashboard->meta()),
}'
exact
class="text-white no-underline dim">
{{ $dashboard::label() }}
</router-link>
</li>
#endforeach
</ul>
#endif
Thx to leek, I was able to find how to retrieve the menus and build on that.
So my first problem was that I was editing the wrong file. You need to do the following first:
copy the file in nova/resources/views/layout.blade.php and put it in
/resources/views/vendor/nova.
After doing this your changes will reflect correctly. I moved all the files in the nova view folder while I was at it.
In side the newly created /resources/views/vendor/nova/layout.blade.php file replace this code:
#foreach (\Laravel\Nova\Nova::availableTools(request()) as $tool)
{!! $tool->renderNavigation() !!}
#endforeach
with this code:
#php
$menus = [
nova_get_menu('admin'),
];
#endphp
<section style="width: 100%; position: absolute; top: 60px;">
<ul class="sidebar-menu">
<li class="sidebar-header">MAIN NAVIGATION</li>
<li>
<a href="/nova">
<i class="fa fa-dashboard"></i> <span>Dashboard</span></i>
</a>
</li>
#foreach ($menus as $menu)
#continue(is_null($menu))
<li>
<a href="">
<i class="fa fa-dashboard"></i> <span>{{ $menu['name'] }}</span> #if ($menu['menuItems'])<i class="fa fa-angle-left pull-right"></i> #endif
</a>
#if ($menu['menuItems'])
<ul class="sidebar-submenu">
#foreach (($menu['menuItems'] ?? []) as $item)
<li>
#if ($item['type'] === 'text')
{{ $item['name'] }}
#else
<a href="{{ $item['value'] }}"
target="{{ $item['target'] }}"
#if ($item['target'] === '_blank') rel="noopener" #endif><i class="fa fa-circle-o"></i> {{ $item['name'] }}</a>
#endif
</li>
#endforeach
</ul>
#endif
</li>
#endforeach
<li>
<a href="/nova/logout">
<i class="fa fa-sign-out"></i> <span>Logout</span></i>
</a>
</li>
</ul>
</section>
Replace "admin" with the slug of your menu
You can change the HTML to what ever you want.
I used https://www.jqueryscript.net/menu/Stylish-Multi-level-Sidebar-Menu-Plugin-With-jQuery-sidebar-menu-js.html
And the result is:
You can add more then one menu like this if you need to
#php
$menus = [
nova_get_menu('admin'),
nova_get_menu('user'),
nova_get_menu('pages'),
nova_get_menu('configuration'),
nova_get_menu('store'),
];
#endphp
The foreach loop will add them all to your page in the order you put them in the $menus array.
Good luck!
Quote from this issue on GitHub:
[nova_get_menu()] only returns a PHP array. You have to handle creating the HTML yourself.
As of version 2.3.7, you will need to use this function yourself to generate your own menu HTML:
$menuJson = nova_get_menu('admin')
// Returns:
// [
// 'id',
// 'name',
// 'slug',
// 'locale',
// 'menuItems' => []
// ]

Yielding HTML inside of a slot doesn't work for components

So I have this simple admin toolbar:
<div class="admin-toolbar {{ $class ?? '' }}">
<i class="fas fa-user-shield"></i>
{{ $buttons }}
</div>
And I use it as such:
#admintoolbar
#slot('buttons')
<a href="/snippet/destroy/{{ $snippet->id }}">
<i class="margin-left(8px) far fa-trash-alt"></i>
</a>
#endslot
#endadmintoolbar
Surprisingly, I get Undefined variable: buttons at line {{ $buttons }}

unexpected "=" in operand

I am getting this error in a Hugo theme and have modified the code to use a simple example from the Hugo documentation and still get an error.
unexpected "=" in operand
Hugo Version
Hugo Static Site Generator v0.40.1 linux/amd64 BuildDate: 2018-04-25T17:16:11Z
Go Version
go version go1.12 linux/amd64
I have copied this code directly from the GoHugo - Append example.
Error
ERROR 2019/03/11 09:24:53 theme/partials/work.html : template: theme/partials/work.html:3: unexpected "=" in operand
Simplified Template
{{ partial "global-header.html" . }}
{{ $s := slice "a" "b" "c" }}
{{ $s = $s | append "d" "e" }}
<h1>David</h1>
I originally got the error in the Hugo AirSpace template at line 13 of the work.html partial.
Sample Line
{{ $categories = $categories | append .category }}
Full Template
{{ partial "global-header.html" . }}
<!-- Portfolio Start -->
<section id="portfolio-work">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="block">
<div class="portfolio-menu">
<ul>
{{ $categories := slice }}
{{ range .Site.Data.work.portfolio }}
{{ $categories = $categories | append .category }}
{{ end }}
<li class="filter" data-filter="all">Everything</li>
{{ range ( $categories | uniq ) }}
<li class="filter" data-filter=".{{ . }}">{{ . }}</li>
{{ end }}
</ul>
</div>
<div class="portfolio-contant">
<ul id="portfolio-contant-active">
{{ range .Site.Data.work.portfolio }}
<li class="mix {{ .category }}">
<a class="venobox" href="{{ $.Site.BaseURL }}{{ .image }}">
<img class="img-responsive" src="{{ $.Site.BaseURL }}{{ .image }}" />
<div class="overly">
<div class="position-center">
<i class="fa fa-search fz-20"></i>
<h2>{{ .name }}</h2>
<p>{{ .description }}</p>
</div>
</a>
</li>
{{ end }}
</ul>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Clients Logo Section Start -->
<section id="clients-logo-section">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="block">
<div id="clients-logo" class="owl-carousel">
{{ range .Site.Data.work.clients }}
<div class="clients-logo-img">
<img src="{{ $.Site.BaseURL }}{{ .image }}" alt="Features">
</div>
{{ end }}
</div>
</div>
</div>
</div>
</div>
</section>
I found that my version of go was old and it needed updating to 1.11
I followed the instructions found here
install-go-1-11-on-ubuntu
I had one slight variation, I used Go1.12 instead of 1.11
# From the docs
sudo tar -xvf go1.11.linux-amd64.tar.gz
# This is the latest version when I updated
sudo tar -xvf go1.12.linux-amd64.tar.gz
I also had to update my version of hugo.
Any time I did the following
sudo apt-get install hugo
I ended up with version 40
I followed the instructions here to go to version 53 of GO

How To use #parent of blade to add li to ul

I'm trying to use #parent to append li to ul to bulidbreadcrumb
this is my header code
(master.blade.php)
<ul class="breadcrumb">
#yield('breadcrumb')
</ul>
and this is my code in the view (index.blade.php)
#layout('layouts.default')
#section('breadcrumb')
<li> {{ HTML::link('','Brands') }} </li> #parent
#endsection
and this is the material i follow
http://laravel3.veliovgroup.com/docs/views/templating
#parent not work for me , i need help
thanks
You need to have #parent in your layouts.default so it echos the parent content.
http://laravel.com/docs/templates
#layout('layouts.default')
#section('breadcrumb')
#parent
<li> {{ HTML::link('','Brands') }} </li>
#endsection
#parent should be in a new line.
if you want that put #parent after, will work too.
#layout('layouts.default')
#section('breadcrumb')
<li> {{ HTML::link('','Brands') }} </li>
#parent
#endsection
I believe that #parent works in somewhere, but i tested only at begin and end.
#layout('layouts.default')
#section('breadcrumb')
<li> {{ HTML::link('','Brands') }} </li>
#parent
<li> {{ HTML::link('','Brands') }} </li>
#endsection
If you want, Laravel 4 brought many improvements to blade template.
Sorry my bad english. I tried write better.

Resources