so I have this volt code:
views/administrator/index.volt
{{ content() }}
{% set user = session.get('user') %}
<br />
<div class="row">
<div class="col-xs-12 col-md-12 col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" href="#container_userForm">
<span class="glyphicon glyphicon-asterisk"></span>
<b style="color: green;">New user</b>
</a>
</div>
<div id="container_userForm" class="panel-collapse collapse">
<div class="panel-body">
{% include "administrator/" ~ user['role'] ~ "-form-user.volt" %}
</div> <!-- end panel body -->
</div>
</div>
</div>
</div> <!-- end row -->
views/administrator/moderator-form-user.volt
exist and has some content.
but when I run the code, I have this error
View '/var/www/html/phalcon-dash/app/config/../../app/views/administrator/moderator-form-user.volt' was not found in the views directory
I took out the user['role'] and use {% include "administrator/moderator-form-user.volt" %}, it works normally (user['role'] = 'moderator')
can anyone explain to me why it happens and how to work around it, I'll need to implement more roles in the future, and I don't want to have multiple if-else in volt
Update
This is the answer to the problem
Volt not including file if path is concatenated
Have you tried it with partial?
{{ partial("administrator/" ~ user['role'] ~ "-form-user") }}
I'm guessing something is not right with views directory. Could you check it out as well?
From your controller, you can try this to get your views directory;
$this->view->getViewsDir()
Try to use the slash. Your include probably looks for a folder "administrator" inside of a folder "administrator", where index.volt is.
{% include "/administrator/" ~ user['role'] ~ "-form-user.volt" %}
Related
I am trying to include this comments.index file:
#extends('posts.show')
#section('title', 'Comments')
#section('comments')
Create Comment
#foreach ($comments as $comment)
#if ($comment->post_id == $post->id)
<div class="border margin mb-1">
<div class="border margin">
<p>{{$comment->text}}</p>
</div>
Edit
</div>
#endif
#endforeach
Back
#endsection
From this posts.show file:
#extends('layouts.myapp')
#section('content')
<head>
<link href="{{ asset('css/posts.css') }}" rel="stylesheet">
</head>
<div class="post_container">
<div id="post_title">
{{$post->title}}
</div>
<div id="post_text">
{{$post->text ?? 'Empty'}}
</div>
<div>
<img src="{{ asset('storage/images/'. $post->image) }}">
<p>
{{$post->image}}
</p>
</div>
</div>
<div>
<h2>Comments</h2>
<div>
#include('comments')
</div>
Comments
</div>
Back
#endsection
Now the issue is that when I include 'comments' it throws 'view comments not found' error and asks if I am sure there is a blade file with such a name. This made me think that I need to include 'comments.index', but when I do this I get 'undefined variable $comments' error.
Doing an include of a partial is dot notation. So in this example...
#include( 'includes.modals.dude' )
This is really located in views -> includes -> modals -> dude.blade.php
The file name must be YourName.blade.php.
I think you are providing a relative path, include directive needs absolute path. So, in your case following code should work.
#include('comments.index')
I am new to OctoberCMS and I am stuck now, I am facing issue to use my custom blog posts component (which overrides Rainlab blog posts) in the same page multiple times.
Say I have created an alias of default blogPosts to postLists and I defined my custom HTML structure and it is working well, no issues.
Now what I want is to use the postLists post structure in my page for three different categories and here I am stuck because when I pass variable to component like this - { % component 'postLists' categoryFilter='news' %} it does not work for the category filter and if I select a category from drag drop component UI it becomes global categoryFilter setting for the page.
This is my requirement.
My postList component code:-
{% set posts = __SELF__.posts %}
{% for post in posts %}
<div class="col-sm-6">
<div class="row">
<div class="col-sm-4 col-4 content_body_img">
<a href="{{ post.url }}">
{% if post.featured_images.count > 0 %}
<img class="media-object" src="{{ post.featured_images.first.getThumb(108, 108) }}" />
{% else %}
<img class="media-object" src="http://placehold.it/108x108" />
{% endif %}
</a>
</div>
<div class="col-sm-8 col-8">
<p>{{ post.title }}</p>
<!--location_date-->
<div class="location_date">
<ul>
<li><i class="fa fa-calendar"></i><span> {{ post.published_at|date('j F, Y') }}<span></li>
<li><i class="fa fa-map-marker"></i>Dubai</li>
</ul>
</div>
<!--location_date end -->
</div>
</div>
</div>
<!--content_body_img end -->
{% else %}
<div class="col-sm-6 col-6 col-lg-3">{{ noPostsMessage }}</div>
{% endfor %}
Please help me, any help will be very much appreciated.
Thanks Sanny
This is static Approach - I will post dynamic Approach as well give me some time
Best and possibly easy solution will be ( in case you just intend to show posts ) is to add 3 Post List component with Different Category filter option for each tab.
It should do your work
make sure this is optimal solution if you just need to show lists nothing else.
I'm a newbie in laravel and actually I have to write the sidebar in every blade of the application to make it work, but I'd like using a different sidebar depending on the section of the site where I am.
So this is what I'm trying to do:
EDIT 1
layouts/main.blade.php
<div class="wrapper">
<div class="sidebar" data-color="brown" data-active-color="danger">
<div class="logo">
<!-- Content -->
</div>
<!-- Sidebar -->
#if(request()->is("{{ url('/')}}/{operator}"))
#include('operator.sidebar')
#else
#include('stduser.sidebar')
#endif
<!-- End sidebar -->
</div>
<div class="main-panel">
<!-- Navbar -->
<nav></nav>
<!-- End navbar -->
<!-- Main content section -->
#yield('main-panel')
<!-- End main content section -->
<!-- Footer -->
<footer></footer>
<!-- End footer -->
</div>
</div>
stduser/dashboard.blade.php
#extends('layouts.main')
#section('main-panel')
<!-- Main panel contents -->
#endsection
#section('extrajs')
<!-- script contents -->
#endsection
stduser/sidebar.blade.php
<div class="sidebar-wrapper">
<div class="user btn-rotate">
<div class="photo">
<i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
<div class="info">
<a href="{{ url('/user') }}/profile">
<span>
{{ Auth::user()->name }}
</span>
</a>
<div class="clearfix"></div>
</div>
</div>
<ul class="nav">
<li class="active btn-rotate">
<a href="{{ url('/') }}">
<i class="nc-icon nc-bank"></i>
<p>Companies</p>
</a>
</li>
</ul>
</div>
operator/sidebar.blade.php
<div class="sidebar-wrapper">
<div class="user btn-rotate">
<div class="photo">
<i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
<div class="info">
<a href="{{ url('/user') }}/profile">
<span>
{{ Auth::user()->name }}
</span>
</a>
<div class="clearfix"></div>
</div>
</div>
<ul class="nav">
<li class="active btn-rotate">
<a href="{{ url('/') }}/{{ $operator->id }}/about">
<i class="fa fa-tachometer" aria-hidden="true"></i>
<p>DashBoard</p>
</a>
</li>
<li class="btn-rotate">
<a href="{{ url('/')}}/{{ $operator->id}}/suppliers">
<i class="fa fa-link" aria-hidden="true"></i>
<p>Suppliers</p>
</a>
</li>
<li class="btn-rotate">
<a href="{{ url('/')}}/{{ $operator->id}}/products">
<i class="fa fa-product-hunt" aria-hidden="true"></i>
<p>Products</p>
</a>
</li>
</ul>
</div>
This is how my views are structured:
Is there a way to make it work?
you can include the blade file like so #include('layouts/sidebar_' . $sidebarName) and if you want to avoid errors when include doesnt exist you can use #includeIf('view.name', ['some' => 'data'])
So you have just the include statement and the sidebar content only once
Based on your feedback to addi2113's answer, it seems like you're wanting to switch out the sidebar include based on which page you're on. There are several ways to do this. The simplest (yet least flexible) way to do this would be to show a certain sidebar based on the route. For instance, if you have a predictable route structure for all "operator" pages, such as example.com/operator/*, you could do the following by using an #if statement in your blade view. Like this:
#if(request()->is("/unique/url/pattern"))
#include('operator.sidebar')
#else
#include('stduser.sidebar')
#endif
Obviously, you can edit this to use any logic you want, but this is a somewhat simple way to handle this.
EDIT: Try this in your main.blade instead of using a section and yield:
<div class="wrapper">
<div class="sidebar" data-color="brown" data-active-color="danger">
<div class="logo">
<!-- Content -->
</div>
<!-- Sidebar -->
<div class="sidebar-wrapper">
<div class="user btn-rotate">
<div class="photo">
<i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
<div class="info">
<a href="{{ url('/') }}/profile">
<span>
{{ Auth::user()->name }}
</span>
</a>
<div class="clearfix"></div>
</div>
</div>
#if(request()->is('/unique/url/pattern'))
#include('operator.sidebar')
#else
#include('stduser.sidebar')
#endif
</div>
</div>
</div>
EDIT 2:
Since it appears you are using a dynamic URL for the operator pages, you have two options. The first option is to make your operator routes more unique than they currently are so that you can use an asterisk to denote all routes of a current pattern. For instance, in routes/web.php, change your routes for operator pages to this type of pattern:
Route::get('/operator/{operator}/about','OperatorController#about')->name('operator-about');
By adding the operator slug into the url, you now have a UNIQUE path that you can reference. Then, in your main blade, you would reference all of the operator routes together like this:
#if(request()->is('/operator/*'))
#include('operator.sidebar')
By making the URL unique, you have made a very simple way to reference all routes where you want to show the operator sidebar.
Another option, which is not as robust in my opinion, is to refer to the specific routes by naming. For instance, using the route I defined up above with the name of "operator-about", I could show the operator sidebar like this:
#if(Route::currentRouteName()=="operator-about")
#include('operator.sidebar')
You would then expand upon this by explicitly defining all named routes that you would want to show the operator sidebar for. As you can probably tell, this will get messy if there are a lot of routes you want to include. I don't recommend to do it this way, but you can feel free to solve the problem however you want.
I am doing the CMS, I would like to place the images in different position(I did not use the foreach because the positioning of foreach its either vertical or horizontal). For example i have 4-5 images(So the index will start at 0 until 3/4), the first image/index(which is 0) I would like to place it in the top left, the second image/index(which is 1) I would like to place it in the bottom right etc etc.. Is it possible? If yes how?
Note: I am converting my laravel project into codeigniter, that's why my codes in my view is in the laravel
View
<div class="fh5co-explore">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-pull-1 animate-box">
#if($content[0]['status']=="Activated")
<img class="img-resposive" src="assets/images/{{$content[0]['img_jumbotron']}}" alt="work">
#endif
</div>
<div class="col-md-4 animate-box">
<div class="mt">
<div>
<?php ?>
<h4><i class="icon-user"></i>{{$textcontent['0']['text_header'] }} ?></h4>
<p>{{{ $text[0]['text_description']}}}</p>
</div>
<div>
<h4><i class="icon-video2"></i>{{ $text[1]['text_header'] }}</h4>
<p>{{{ $text[1]['text_description']}}}</p>
</div>
<div>
<h4><i class="icon-shield"></i>{{ $text[2]['text_header'] }}</h4>
<p>{{{ $text[1]['text_description']}}}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I think laravel have default template engine so you can free to use the format what you mentioned in your code.But in codeigniter there no any default template engines.But there an alternate way to use the same method in codeigniter by using Template Parser Class.To enable this you must include the library call parser,
include this in your codeigniter current controller,
$this->load->library('parser');
For more information please refer this documentation,
https://www.codeigniter.com/userguide3/libraries/parser.html
I have a dynamic menu and in the top right corner I want to dinamically display the number of products I have in my cart. All my twigs extend base.html.twig in which I have this dynamic menu.
<div id="mainBody" class="container">
<header id="header">
<div class="row">
<div class="span12">
<img src="{{ asset('bundles/mpshop/img/logo_title.png') }}" alt="Bootsshop"/>
<div class="pull-right"> <br/>
<span class="btn btn-mini btn-warning"> <i class="icon-shopping-cart icon-white"></i> [ {{ cart|length }} ] </span>
<span class="btn btn-mini active">$155.00</span>
<span class="btn btn-mini">£</span>
<span class="btn btn-mini">€</span>
</div>
</div>
</div>
However when I add {{ cart|length }} I am getting variable cart does not exist. Does base.html.twig has its own controller? How to give the base twig the cart with session so it could see my array?
One way to do this is create a helper class and include a method from that class in the menu (navbar?)
To do this you can make a regular Controller called for example HelperController.php then create a method within that new controller, like shownumberofproductsAction and then create a corresponding view file: shownumberofproducts.html.twig
Then in your top right menu simply call:
{% render controller("MySomethingBundle:Helper:shownumberofproducts") %}