Support the ongoing development of Laravel.io →
Database Views Blade

Hi guys,

I'm planning to develop a multi tenancy application which allows users to modify their own templates. To do this, I will store users template in database and render it when needed.

<div> My name is {{{$name}}} </div> -- name.blade.php

View::make('name')->with('name','Ted');

Above is how we normally do.

My problem is, how to pass the Blade template and compile it with data. I do understand Blade have the function called compileString, but it only able to render the given template without data. Example:

$template = Template::get('make'); // custom class where get the template in database, in this case, <div> My name is {{{$name}}} </div> is returned Blade::compileString($template); //where I can't pass name variable to compile.

Hope you guys can help me. Thanks :)

Last updated 2 years ago.
0

Is the template going to be the same but with user data involved? Or, are different users going to have different components? Either way, I would have a single template with variables loaded from the database based on Auth::user(). From there if they user lets say wanted a clock widget on their template have an entry in the database that would make it as true and have an @if statement. That's how I would go about it. Maybe yours is a bit more complex.

Last updated 2 years ago.
0

Well, imagine there are 2 users with 2 database- User A with DB-A, User B with DB-B.

Lets say the index page with 2 different template

User A template:

<html>
<body>
   <div>
       Template for User A {{$userAVariable}}
   </div>
</body>
</html>

User A template:

<html>
<body>
   <div>
       Template for User B {{$userBVariable}}
   </div>
</body>
</html>

Both template will be stored in their own database, lets say a table named "Template"

When render the page, template will be fetch from DB and render it.

Hope this clear about my question.

Thanks

Last updated 2 years ago.
0

I don't think that that is possible, you can look at Twig, that should be possible. See https://github.com/rcrowe/TwigBridge/tree/0.6 and http://twig.sensiolabs.org/doc/functions/template_from_string.html

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ming517 ming517 Joined 19 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.