laravel-shortcodes icon indicating copy to clipboard operation
laravel-shortcodes copied to clipboard

Is it possible to return a variable then is it on the view?

Open ellemaker opened this issue 5 years ago • 10 comments

propose return "<?php $test = {$value}; ?>";

ellemaker avatar Oct 25 '19 15:10 ellemaker

I don't understand your question.

webwizo avatar Oct 25 '19 15:10 webwizo

Screenshot_63 Screenshot_64 Screenshot_65 Screenshot_62

see screenshot

ellemaker avatar Oct 25 '19 15:10 ellemaker

Let me see, what I can do.

webwizo avatar Oct 25 '19 15:10 webwizo

so I want to use $variable in the view like {{ $variable }}

ellemaker avatar Oct 25 '19 15:10 ellemaker

So why need Shortcode? You can use create Blade Extended.

https://laravel.com/docs/6.x/blade#extending-blade

webwizo avatar Oct 25 '19 15:10 webwizo

this is what I'm trying to achieve

[webapp id='123123' collection='listofteams']
	@foreach ($listofteams as $item)
		<li>name</li>
	@endforeach

ellemaker avatar Oct 25 '19 15:10 ellemaker

Nice idea, dude. This feature can be added, but I don't think I can do it earlier :(

But you can create a shortcode and pass the collection, and shortcode will output the FOREACH as a result. :)

webwizo avatar Oct 25 '19 15:10 webwizo

yes, I already made those things. but I want to change the layout in every collections. that's why we want it to foreach in the view.

ellemaker avatar Oct 25 '19 16:10 ellemaker

But you can add one more attribute like [webapp wrap="li" parent="ul"] this way you can create multiple layouts. So it could be DIV or LI or anything.

Also, you can pass a partial view name like [webapp view="orders.grid"] and class function would be like:

$view = view($viewname)->render();
return $view

I think it would work.

webwizo avatar Oct 25 '19 16:10 webwizo

Thank you for helping me on this but I think it would be much easier if the we can use the variable that was return in shortcode or return a php tag(like what is in my screenshot).

ellemaker avatar Oct 25 '19 16:10 ellemaker