Is it possible to call a view inside a view in Laravel?
<div id="main_content">
<?php View::make('content_view'); ?>
</div>
like it nicely worked in Codeigniter
<div id="main_content">
<?php $this->load->view('content_view'); ?>
</div>
You dont 'call' a view, you 'include' the view - see template docs for more examples at Laravel.com
<div id="main_content">
#include('content_view')
</div>
Related
I am using Laravel 6.20.11, and I have published the Laravel blade error templates. What I need to have happen is that if the user is authenticated, the error message extends the internal-only layout, and if not, it extends the public layout like so:
#auth
#extends ('int-layouts.partials.wrapper')
#section ('error')
<div class="be-content">
<div class="main-content container-fluid">
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404 - Not Found</h1>
<p class="text-muted text-uppercase mb-4">Sorry, we couldn't find the page you were looking for.
Please contact the administrator<br/>
Or go back to the <a class="navbar-brand py-1" href="/controlpanel/">Dashboard</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#endauth
#guest
#extends ('ext-layouts.master')
#section('error')
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404</h1>
<p class="text-muted text-uppercase mb-4">Sorry,You are trying to reach the page that does not exist.<br>
Please contact the administrator <br/> Or go back to the <a class="navbar-brand py-1" href="/">Home Page</a></p>
</div>
</div>
</div>
</div>
#endsection
#endguest
The problem I am having is that when I test the 404 error using abort(404) or by trying to access a route that doesn't exist, the error message displays twice and the page inherits the int-layouts.partials.wrapper even when the user isn't authenticated.
Is this expected behavior or am I doing something wrong in my blade file?
You can try to use a conditional in one #extends directive:
#extends (auth()->check() ? 'int-layouts.partials.wrapper' : 'ext-layouts.master')
Then you can use a conditional after this inside your section.
#section('error')
#auth
#else
#endif
#endsection
The #extends directive is not actually returning output directly into the compiled result like most directives do. The compiled PHP for this is held in an array to be added later.
Everything inside the ( ) of the directive is being used as a literal to call make on the View Factory:
"<?php echo \$__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>"
If you found the compiled view for this Blade template you would see this:
<?php echo \$__env->make(auth()->check ? 'int-layouts.partials.wrapper' : 'ext-layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
The first argument to make ends up being your view name when this compiled view is executed.
In Controller function:
$layouts = Auth::user->admin ? 'view.admin' : 'view.student'; //
view.admin or view.student is the blade file which you want to render
dynamically.
return view('welcome',compact('layouts'));
Write in Blade File:
#extends($layouts)
#section('...')
...
#endsection
In my app, i use get_instance() in my view, below is my complete code
<h3 class="title">
<?php echo get_instance()->router->fetch_method();?>
</h3>
what it is dangerous?
i move breadcrumbs, but now i need that Title Page show below, actually html show
<div class="breadcrumbs"></div>
<div class="col-main">
<div class="my-account">
<div class="page-title"></div>
</div>
</div>
I need
<div class="breadcrumbs"></div>
<div class="page-title"></div>
<div class="col-main">
<div class="my-account"></div>
</div>
How can i do this, i suposse is necessary modify xml file but i not find the solution.
Thanks
Well, I choose create new custom block in page.xml
<block type="core/template" name="my_top_title" as="my_top_title" template="page/html/toptitle.phtml"/>
In 2columns-left.phtml,
<?php echo $this->getChildHtml('my_top_title') ?>
In toptitle.phtml
<?php $title=$this->getLayout()->getBlock('head')->getTitle(); ?>
<div class="my-title">
<h1><?php echo $title ?></h1>
</div>
Works fine.
I am using CI with Twitter Bootstrap for a basic site:
In my main layout view this is how the main content area is setup:
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span8">
<?php echo $this->load->view($subview); ?>
</div>
<div class="span3" id="sidebar">
<?php echo $this->load->view($this->global_data['sidebarview']); ?>
</div>
</div>
</div>
One sidebar view is this:
<div class="container-fluid" id="sidebar-about">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-info-sign"></i> More about us</li>
<li class="active">Who are we?</li>
<li>Why we did it?</li>
<li>What we promise?</li>
<li class="nav-header"><i class="icon-asterisk"></i> Services</li>
<li>Free</li>
<li>Premium</li>
</ul>
</div><!--/.well -->
</div><!--/span-->
Every link in this sidebar i want to update the div with class="span8" from my main layout.
How should i do that? Should i use ajax calls to update the content of the span8 div? or just create more methods in about controller?
Joomla Geeks!
Please help me. Web designers created design for Joomla, where
<jdoc:include type="message" />
should be located inside of custom component's view (default.php). It's because of divs nesting, I can't change anything.
Nevertheless, I have to find a solution to include Joomla system messages in component's view (default.php) instead of template's index.php, how to do that? Is it possible?
UPD: I've solved the problem, but now I need to override this code:
<dl id="system-message">
<dt class="message">MESSAGE_TYPE</dt>
<dd class="message message fade">
<ul>
<li>MESSAGE_TEXT</li>
</ul>
</dd>
</dl>
with this one:
<div class="message">
<span class="jsMessage info_message">
<span>
MESSAGE_TEXT <a class="close jsCloseMessage" href="javascript:void(0)"></a
</span>
</span>
</div>
Should I use templates/mytemplate/html/modules.php file for that?
$document = & JFactory::getDocument();
$renderer = $document->loadRenderer('message');
$msg=$renderer->render();