Laravel - Breadcrumbs module : pass array of arguments - php

I am using this module .
I defined my Breadcrumbs, and now I'm trying to render in my blade template by doing the following :
{!! Breadcrumbs::render($breadcrumbs) !!}
The value of $breadcrumbs being "controlled" by my controller.
The problem is that I would like to be able to pass an array of arguments to this render() method, and not only simple strings. Indeed, here are some Breadcrumbs I declared :
Breadcrumbs::register('home', function($breadcrumbs)
{
$breadcrumbs->push('Home', route('home'));
});
/* .... etc .... */
Breadcrumbs::register('style', function($breadcrumbs, $style_name, $style_slug)
{
$breadcrumbs->parent('styles');
$breadcrumbs->push($style_name, route('style', $style_slug));
});
In this situation, I need to be able to pass an array of arguments to the render() method, which will be sent by the Controller to the View.
I tried the following :
{!! call_user_func_array(Breadcrumbs::render, $breadcrumbs) !!}}
But I get the following error :
Undefined class constant 'render'

This module has a renderArray() method. Next time, I'll read the documentation till the end :)

Related

OctoberCMS global page properties?

Is it possible to set a series of global properties (such as social media usernames) that are available to all page views in OctoberCMS rather than having them associated to one CMS page or Static Page at a time?
For example, being able to use {{ twitter_username }} in any template, but it wouldn't show up as a field in any page form on the backend.
UPDATE: this can be achieved by registering a Twig function using registerMarkupTags in your plugin:
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function registerMarkupTags()
{
return [
'functions' => [
'globals' => function($var) {
switch ($var) {
case 'twitter_username':
return 'mytwitterusername';
}
return null;
},
],
];
}
}
In this case, calling {{ globals('twitter_username') }} from any template prints mytwitterusername.
Hmm yes better you need to add code to life-cycle method in layouts, so now page which are using that layout will have this info already loaded.
In layout code block you can use something like this
use RainLab\Pages\Classes\Page as StaticPage;
function onStart() {
$pageName = 'static-test'; // this will be static page name/filename/title
$staticPage = StaticPage::load($this->controller->getTheme(), $pageName);
$this['my_title'] = $staticPage->viewBag['title'];
$this['twitter_username'] = $staticPage->viewBag['twitter_username'];
}
now inside your cms page you can use this variable
<h1>{{ my_title }} </h1>
<h3>{{ twitter_username }} </h3>
let me know if it you find any issues
You could also use theme config file which gives you more flexibility rather than hardcoding the values in to the code block.
https://octobercms.com/docs/themes/development#customization

Laravel - Call Crypt::decrypt() in blade template

i'm using datatables serverside to get all the data from 2 tables and display them. One of the values that i get is encrypted in the database.
Is there any way to decrypt this value within the blade template before displaying it?
I'm editing other values of the tables using
"mRender": function (data, type, full) {}
Tried to use Illuminate\Support\Facades\Crypt::decrypt($value) but it has no result.
I got the solution as below.
{{ \Crypt::decrypt($var) }}
You can use only decrypt function too
{{ decrypt($var) }}
full[5] is a javascript variable, if you pass it to Crypt::decrypt() it will not know it is a javascript variable, but a php constant, because it is inside <?php ?>.
You need to "rebuild" your data the way you want it to be displayed in datatables.
To do so, use editColumn method:
Route::get('/serverSideSymv', ['as' => 'serverSideSymv', 'uses' => function () {
$symv = App\Symvolaia::Select('table1.*')->join('table2', 'table1.insurancecompanyid', '=', 'table2.id')->join('table3', 'table1.simvalomenos', '=', 'table3.kodikos_pelati')->select('filed1,field2,field3,......');
return Datatables::of($symv)
->editColumn('your_column', function($data) {
return Illuminate\Support\Facades\Crypt::decrypt($data->your_column);
})
->make();
});

Passing data from controller to laravel nested view

I have a page system in Laravel - where I pass data from controller to view.
$this->data['title'] = $row->title;
$this->data['breadcrumb'] = $row->bc;
Now I passed it as follows:
return View::make('Themes.Page', $this->data);
In the view file, I access the data as follows:
{{$breadcrumb}}
What I am trying to do now is to pass this data in nested views:
$this->layout->nest('content',$page, $this->data);
(Content is the {{content}} in the view which will be replaced with $page contents. I want to pass the $this->data just as before but now I get an error:
Variable breadcrumb not defined.
Note: Laravel Version 4.2 $this->layout is set in constructor to a
template file (Themes.Page)
Actually you don't need to pass any separate data to your partial page(breadcrumb)
controller page
$this->data['title'] = $row->title;
$this->data['breadcrumb'] = $row->bc;
return View::make('idea.show',array("data"=>$this->data));
main view page
<div>
<h1>here you can print data passed from controller {{$data['title']}}</h1>
#include('partials.breadcrumb')
</div>
your partial file
<div>
<h1>here also you can print data passed from controller {{$data['title']}}</h1>
<ul>
<li>....<li>
<li>....<li>
</ul>
</div>
for more information on this you can check following links http://laravel-recipes.com/recipes/90/including-a-blade-template-within-another-template or watch this video https://laracasts.com/series/laravel-5-fundamentals/episodes/13
You should pass data as follows
return View::make('Themes.Page')->with(array(
'data'=>$this->data));
or (since you're passing only 1 variable)
return View::make('Themes.Page')->with('data', $this->data);
and further you can pass it on to nested views as by referencing $data
$dataForNestedView = ['breadcrumb' => $row->bc];
return View::make('Themes.Page', $this->data)->nest('content', 'page.content', $dataForNestedView);
In the Themes.Page view render nested view:
<div>
{{ $content }} <!-- There will be nested view -->
</div>
And in the nested page.content view you can call:
<div>
{{ $breadcrumb }}
</div>
*div tag is only for better understanding.
Okay, after intense search, I figured out that there was a bug in the Laravel version 4.2 I was using.
Laravel 5 works.
For laravel 4.2, a better option would be to pass array of data objects using View::share('data',$objectarray) while passing the data from controller.
Thanks everyone for help

Symfony2 getting the url of request in subrequests in twig

How can I get the current url in a subrequest and change parameters with it(for example locale).
I have main action that renders the template.
public function indexAction() {
return $this->render('MpShopBundle:Frontend:index.html.twig', array(
'products'=>$products,
'locale' => $locale,
));
}
In the template I render the navigation like this:
<span class="top">{% render controller("MpShopBundle:Navbar:navbar") %}</span>
Now in this navbar template I am trying to do this:
{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({'_locale': 'en'})) }}
I am getting an empty url because this is a subrequest... How can I pass the URL to the subrequest? This is the first time im dealing with them..

Blade helper, get variable from view without parameter

maybe someone know, how can I get variable with name "foo" from blade template get to static function which is used in this template.
For example I have:
<div class="collumns large-8">
{{ Helpers::setLetters('variable_name') }}
</div>
<div class="collumns large-8">
{{ $variable_name }}
</div>
Both divs should set same string because in setLetters function will be
return ${$name};
But, that should be instead $name, because in case about, will be error.
I use laravel 4.1
This doesn't go in your View, it should be in your controller.
Controller
$name = Helpers::setLetters('variable_name');
return \View::make('yourview', array( 'variable_name' => $name);

Categories