How to extend layout based on database - laravel

I want to extend a layout which the folder name is retrived from database. Bellow is the code.
#extends('layout.'.{{ $layout->layout}}.'.main')
But it is not working, what is the logic behind getting layout name from database? Please let me know.

you don't need the blade brackets {{ }}. The brackets are short for
#extends('layout.' . $layout->layout . '.main')
I didn't test it but it should work.

Related

How to render multiple livewire component as string?

I have multiple livewire components e.g. opd.patient-count, opd.visit-count, opd.checkup-count and so on. I would like to store these components name into database then call by user role. Anyway, It does not work once I tried as below.
foreach ...
echo '<livewire:opd.patient-count />';
endforeach ...
Any advice or guidance on this would be greatly appreciated, Thanks.
As I understand your problem, You can achieve using this syntax instead
#foreach($components as $eachComponent)
#livewire($eachComponent,['componentData' => $data])
#endforeach
in this code above, the component name is assigned accordingly using a blade #foreach directive and iterate over each element and make the component.

Is it possible to manipulate the output of a laravel #yield in the blade template?

Wondering if it is possible to manipulate the output of a #yield in Laravel? In short I have a title in my child template that I would like to set some id's with to make them unique. I know I could just create another #section('id', 'asdf') but rather not have to worry users with that especially since the title has to be unique anyways...
Could not find anything that says this is possible?
Example (which fails) but what I am essentially trying to do:
id="{{Str::kebab(#yield('title'))}}-preview-tab"
#yield gets replaced with a PHP echo statement so that is not what you want. If you want the content of a section you can grab it from the View Factory:
$__env->getSection($name, $default)
Or even calling yieldContent:
$__env->yieldContent($section, $default)
So you could try:
{{ Str::kebab($__env->getSection('title', 'some default if you want')) }}
If you have any issues with that, try the yieldContent method.

How to generate Laravel Link with anchor

I use Laravel URL::Route for link pages, And I passed query string like following code, but how to add anchor tag for this?
eg: myproject.local/projects?week_ending=value#anchor
How to do that #anchor part with URL::Route? thank you
URL::Route('projects', array('week_ending'=>$week_end_day))
The most obvious way for that will be:
URL::Route('projects', array('week_ending'=>$week_end_day)) . '#anchor'

How to keep the line breaks from user input but also sanitize in blade?

I try to render an data from user textarea input saved in my database.
I need to keep the line breaks use nl2br,
and also want to santize to prevent malicious script by using blade {{{ }}}.
But {{{ nl2br($output) }}} wont work, the br tag would also be sanitize.
Please give me some hint, thanks.
For Laravel 4 users:
{{ nl2br(e($message)) }}
e($x) is equivalent to {{{ $x }}}.
Laravel 5 users:
{!! nl2br(e($message)) !!}
e($x) is equivalent to {{ $x }}.
Sawny's answer is a great one that really leverages the power of the Blade syntax well, except I would take it a step further. You can use Blade::extend to create your own Blade # shortcodes so I use the following:
Blade::extend(function($value, $compiler)
{
$pattern = $compiler->createMatcher('nlbr');
return preg_replace($pattern, '$1<?php echo nl2br(e($2)); ?>', $value);
});
Now in your Blade template all have to do is something like this:
<div>#nlbr($sometext)</div>
EDIT: I realized someone coming across this may very well wonder, "Where do I put the Blade::extend function?"
To be honest, it can go in a lot of places (and it depends on if you're using Laravel 4 or 5 as to the 'best' approach).
A simple place to put it is in the routes.php or global.php files as they will get picked up with the least effort. These are however, not the best files to put them in and you would be best off learning to create Laravel Providers.
simply use this remove br no need to write
this function nl2br
it work fine
{!!($mylogin->title) !!}

Smarty getting page content

I need to edit a page on prestashop, I've found that code
<ul id="idTab2" class="bullet">{$agencies->content}</ul>
And where should i search for that $agencies variable ?
I have found the text which is being displayed into that place in CMS.
However I'd that variable need to be define somewhere, am I right ? Anyone knows where should i search for that ? I'm new to prestashop.
Why am i asking for this ? I need to add another page for example
<ul id="idTab2" class="bullet">{$test->content}</ul>
- but I can't just simply add another page called test.
The {$agencies} variable is being set in a object derived from either the Controller or Module classes but to be honest it looks like you're working with code that has been customised (via a class override or a module) making it impossible to provide a definitive answer to your question without knowing more detail.
If you can locate the term 'agencies' in a file located under \controllers, \modules or \override in your installation, then you will be closer to finding your answer. It will be contained in a function call similar to:
$this->context->smarty->assign('agencies' , [some-variable]);
Note that the parameters to the function may also be passed as an array for multiple assignments.

Resources