How to change the default setFlash () in CakePHP ?
How or where change this default element:
<div id="flashMessage" class="message">
My message.
</div>
Necessary:
<div id="myid" class="myclass">
My message.
</div>
Thanks.
According to the documentation:
Create the file app/View/Elements/flash_custom.ctp and build our custom flash element:
<div id="myid"><?php echo $message; ?></div>
Then call setFlash() with those parameters:
<?php
$this->Session->setFlash('My message.', 'default', array('class' => 'myclass'));
The output in your template from using $this->Session->flash() with the above example would be then:
<div id="myid" class="myclass">My message.</div>
Related
I want to make #yield('dynamic') to load different pages like single page application in laravel.
Route:
Route::get(
'/front-office-setup/{setup_type}',
'AdmissionFrontOfficeSetupController#index'
)->name('frontofficesetupview');
Controller:
public function index($setup_type)
{
$data['setup_type'] = $setup_type;
return view('frontoffice::frontofficesetup.frontofficesetup', $data);
}
View:
<div class="row">
<div class="col-md-3">asdf</div>
<div class="col-md-4">asdf</div>
<div class="col-md-5"> #yield('{{$setup_type}}')</div>
</div>
Section:
#extends('frontoffice::frontofficesetup.frontofficesetup')
#section('visitor-purpose')
sdfasd
#endsection
But it doesn't render or show in #yield('{{$setup_type}}')
Is there any way to do this?
Edit part*
Also i have already included a #yield type of things in view file
#extends('backend.master.master')
#section('content')
<div class="row">
<div class="col-md-3">asdf</div>
<div class="col-md-4">asdf</div>
<div class="col-md-5"> #yield($setup_type)</div>
</div>
#endsection
#yield is already started PHP tag <?php. SO no need to mention braces again{{}}. Simply try #yield($setup_type) It will work perfectly.
Currently, I have my directives being switched out in this fashion.
In my directive:
(function(){
'use strict';
var controller = ['$scope', function ($scope) {
}];
angular
.module('moduleName', ['myDependency'])
.directive('dirName', function($compile, $window){
return{
restrict: 'E',
replace: true,
require: [ '^?myDependency'],
scope: false,
controller: controller ,
template:
`<div ng-switch="templateConfig.type">
<div ng-switch-when='con1'>
<p> Config 1 </p>
</div>
<div ng-switch-when='con2'>
<p> Config 2 </p>
</div>
<div ng-switch-when='con3'>
<p> Config 3 </p>
</div>
</div>`
And in the PHP file, I have the following:
function pageController($scope, $http, $filter, $cleo, $timeout, $compile) {
$scope.templateConfig= {type: 'Con2'};
}
<div class="row-fluid">
<div class="span1" id="title" > name </div>
<div class="span11">
<dirName>
</dirName>
<br/>
</div>
</div>
<div class="row-fluid">
<div class="span1" id="title" > name2 </div>
<div class="span11">
<dirName>
</dirName>
<br/>
</div>
</div>
So how it works is that when I can switch between templates using {type: 'Con2'}. However, this will affect both <dirName></dirName> tags. What I want is for me to have the ability to define them independently of each other.
What I want would be something like <dirName templateConfig=Con1></dirName>. I not entirely sure how to achieve this though but I don't think it should be too difficult to make the switch.
Also, I did leave out a lot of code from the PHP file and changed the original names in the code but none of that should be relevant.
Use the function form of the template property:
app.directive('dirName', function($compile, $window){
return{
restrict: 'E',
template: function (elem, attrs) {
switch(attrs.templateConfig) {
case 'con1':
return `<p> Config 1 </p>`;
case 'con2':
return `<p> Config 2 </p>`;
case 'con3':
return `<p> Config 3 </p>`;
};
}
};
})
Example usage:
<dir-name template-config="con2">
</dir-name>
Update
From the Docs:
template
Value may be:
A function which takes two arguments tElement and tAttrs (described in the compile function api below) and returns a string value.
— AngularJS Comprehensive Directive API Reference - template
I'm new to using Plates template library for PHP. I have a few questions about how to use it.
I'm looking through the docs I don't see a way to set a global layout. Is there not a way to do that?
I'm using it inside of Codeigniter. Ideally, I'd like to set the layout in the MY_Controller file for most of the site and change when needed in a controller extending MY_Controller; for instance, setting the main site layout and then for the admin panel setting the admin layout in the Auth_Controller that all of the other admin controllers extend.
Changing the layout of a particular set of templates I'd have to go through and edit all of those files. This doesn't seem ideal. Or even just passing a sidebar data for a particular layout has to be done by passing the sidebar data to each template and from each template to the layout in every file. This seems very redundant. Am I missing something?
To clarify Plates is the template system/library, http://platesphp.com/
Example of what I'm talking about.
The admin layout has a sidebar of all the admin URLs. This comes from a config file that's loaded and it has it's own template/view file.
I call the template and pass the data from the controller
// I created a library file that extends the Plates library so it can be easily loaded from the CI loader class
$data['sidebar_data'] = array(
'navigation'=>'Navigation',
'assets'=>'Assets',
'config'=>'Config'
);
$data['controller_name'] => 'Users';
$this->plates->render('admin/whatever_page', $data);
Inside of the template file/current page
<?php $this->layout('layouts/admin', ['title' => $controller_name, 'sidebar_data' => $sidebar_data])
// stuff for this page
?>
Inside of the sidebar navigation template that gets loaded in the admin layout file
<ul class="menu vertical">
<?php foreach($sidebar_data as $url => $label):?>
<li>
<?= $label ?>
</li>
<?php endforeach; ?>
</ul>
Then the layout
// there's a HEAD method in here that has the $title variable
<header class="row expanded collapse">
<div class="column">
<div class="top-bar">
<div class="top-bar-left">
<ul class="menu">
<li>
<strong>Site Name</strong>
</li>
</ul>
</div>
<div class="top-bar-right">
<ul class="menu dropdown align-right" data-dropdown-menu>
<li>
<?= $current_user ?></a>
</li>
<li class="divider"> | </li>
<li>
<?= $this->insert('auth/logout_form') ?>
</li>
</ul>
</div>
</div>
</div>
</header>
<section id="content">
<div class="left-panel">
<?= $this->insert('adminnav', ['sidebar_data' => $sidebar_data])?>
</div>
<div class="main-panel">
<?= $this->section('content')?>
</div>
</section>
<div id="adminmodal" class="reveal" data-reveal>
<button class="close-button" type="button" data-close aria-label="Close modal">
<span aria-hidden="true">×</span>
</button>
<div class="modal-body"></div>
</div>
<script type="text/javascript">$(document).foundation()</script>
<?= $this->insert('_blocks/googleanalytics')?>
Having to pass the same data from every controller method to the controller's view/template then from that to the layout/other templates is very redundant.
Convert the array to json
for example:
$this->plates->render('admin/whatever_page', ["data" => json_encode($data)]);
In
#dektrium/user/views/admin/_account.php
#dektrium/user/views/admin/_info.php
#dektrium/user/views/admin/_profile.php
there are
<?php $this->beginContent('#dektrium/user/views/admin/update.php', ['user' => $user]) ?>
'the rest codes'
<?php $this->endContent() ?>
and in #dektrium/user/views/admin/update.php there're
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-body">
<?= $content ?>
</div>
</div>
</div>
the $content will be replaced by code between 'beginContent' and 'endContent', how to implement this kind of layout in my new backend model 'Rayon'? I tried write a similar CRUD code, but keep getting an error 'Undefined variable content'.
Thank you for your help.
the row with code
<?php $this->beginContent('#dektrium/user/views/admin/update.php', ['user' => $user]) ?>
tells to the "view" which is, to take the code from the reference and add it to the place where the call is invoked ..
It performs an equivalent action to "include" within more the possibility of pass the variables to use in the "content"
then you should create the part of view that you want to reuse .. and the views in which you want to call to add this type of call
You can do something similar directly reusing the render () function inside de view and indicating which (other) view and which variables to use.
for (simple) example
view container_view.php in yourapp/views
<div>my container test</div>
<?= $content ?>
then
You want that the code in container_view is placed in a way that the code inside beginContent and endContent of the
create.php in yourapp/views/ is place in the same place you have $content in the container
<?php $this->beginContent('yourapp/views/container_view.php', ['model' => $model]) ?>
<div>this code is placed in $container</div>
<div>and the value of the var model is passed</div>
<br />
<?= $model->name '>
<?php $this->endContent() ?>
I have a <h1> tag in my template blade, its duplicate in all pages of my website. I want to do a condition if the page is Homepage then use this <h1> else don't write it.
This is my header code
<div class="col-sm-7">
<div class="slogan">
<h1 id="h1" class="tlt">my h1 Tag</h1>
<span id="span" class="tlt">" {{$slogan[0]->text}} "</span>
</div>
</div>
Thanks
You can use Request::is('/'), given that the "homepage" is on this url. The is() method can also accept wildcards which can be useful for stuff like Request::is('admin/*');.
If you have a route name for your routes, you can do like this in your view:
Route:
Route::get('/', ['as'=>'home', 'uses'=>'HomeController#index']);
In view:
#if(request()->route()->getName() == 'home')
// <h1> Text for home page </h1>
#else
//text for other pages.
#endif