Laravel - Use blade syntax pulled from MySQL in view - laravel-5

I have articles stored in MySQL. Also images stored in database. Using {!! $myarticle->content !!} works great to display the article rendered but if I use {{$myImage}} inside the stored article it gets rendered as is not as the blade variable.
Is there a way to insert that into or pull it out of MySQL so that when it gets to the view it will work as the blade variable?

Related

How to display my tinymce text into my html view

I save into my database the text which I write into a textarea with tinymce.
What I'm trying to do now, is to display this content into my view. Right now, when I'm doing {{$article->contenu}} i've this :
Is there a way to display my tinymce content into my view with the correct format please (not inside a textarea) ?
Content from TinyMCE is saved as an HTML string. You are passing that HTML content to Laravel's templating engine as a variable, and asking it to to be rendered. By default Laravel does not automatically render HTML, to prevent XSS attacks.
However, if you use this syntax instead:
{!! $article->contenu !!}
...the content should render as expected. For more info, check the Laravel docs:
https://laravel.com/docs/5.6/blade#displaying-data

Vue.js - rendering initial products as HTML with Laravel

I'm using Laravel and Vue to show products for a shop. The initial products are loaded through Laravel and sent to the view, and then they are fed to the vue script as initial data. This data is then used to render the page at load. After this, when changing a filter, vue gets the new data async from the server and changes the products. It all works fine.
But I would like to be able to render the initial products without Javascript for SEO-purposes. The only idea I got, is:
Render initial products with a Laravel Blade foreach-loop
Don't feed any initial data to vue
When new content should be loaded, remove this initial PHP-rendered data and activate the v-for loop.
But it's not the prettiest solution. Any ideas on how to make this better?
You need to achieve SSR (server-side rendering) for your APP.
Some options described here - https://v2.vuejs.org/v2/guide/ssr.html

Passing a YAML frontmatter variable from a page to a collection in Jekyll?

So i have a collection called components. The components are a series of small HTML objects with some data in.
I want to pull these components into a page, and be able to pass overriding YAML frontmatter from the page into the component to determine a couple of things on the component.
Is this possible?
I'm pulling specific components onto a page using the following syntax:
{{ site.components | where:"component_name","event-title" }}
but i'd like to be able to do something like:
{{ site.components var-page-state="offline" | where:"component_name","event-title" }}
I chose to use a collection than a series of includes, as i need to loop through the collection and generate/render an index page of all of the components on it automatically.
EDIT:
So i want my component to be able to output a variable set on the page it's included on.
component.title.html:
<h2 class="title">{{ page.var-page-status }}</h2>

Laravel: How to use composer to inject data across all views?

I want to offload some HTML sections of my site into partials (includes) files rather than repeating the information in each view or layout. However, I also need them to contain specific data. An obvious example is the head section; I would like to put this into a partial, however I also want to be able to set the document title and META fields for each page.
I think the best way is to use Laravel's view-composer
As per the docs, I can use an array to define the composer for multiple views at once:
View::composer(array('view1','view2', 'view3'), function($view)
{
$view->with('count', User::count());
});
However, what if I want to use this composer for every view, as I do in this case?
There's a few answers kicking around SO (such as this one) which suggests I use a wildcard. So here's my code:
View::composer('*', function($view)
{
$view->with('header', View::make('partials.head', $view->getData()));
$view->with('footer', View::make('partials.footer', $view->getData()));
});
Here's the problem: Using this is currently giving me an out of memory error, which suggests that it is very inefficient (and therefore that I really shouldn't be doing this).
So do I really need to pass an array listing every page on my website?
Isn't there a way to use composer for every page rendered, like I can with View::share(); ?
If the data is going to be unique for each view, there's no point in putting it in a view composer; you can do this just by using blade templates, and pass the page-specific data to the view from your controller.
Set up header and footer partials, then set up a base template that uses #include to load your header and footer partials, then a section for your content with #yield('content').
<!DOCTYPE html>
...
#include('partials.header')
#yield('content')
#include('partials.footer')
...
Then your individual page's views would each extend this base template:
#extends('base')
#section('content')
//...specific page content here
#stop
In your header and footer partials, include {{ $someData }} for whatever specific needs to change from page to page, and pass that data to each view from the controller.
This is now possible in Laravel 5.5
Put this is your AppServiceProvider boot method:
View::share('data', [1, 2, 3]);

how to convert ajax variable to scala variable in play scala framework

how can i convert the variables in ajax.
<li ng-repeat="item in newsItems | filter:q" style="background-color: white;">
{{item}}</br>
{{item}} displays data in the browser. but i want to transfer this item data to the scala side. the one with the #, because i need the item in:
#form(routes.Application.newItem({{item}})){....}
whenever i run this. it displays.
item not found.
what i want is a step or anything to convert this ajax data to the scala side variable.
You can't do that directly, keep in mind that JavaScript is client-side technology and Scala template is backend one. That means that Play compiles the view long, long before the client (and its JS) will see it.
You have 2 solutions:
Replace action attribute of form tag using JavaScript
You can also use Play's JavaScript routes to create url (also using javascript after page rendering)

Resources