Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cptnflx's avatar

Rendering PHP, SCSS, JS, Blade-Files from Blade-Files

Hey guys,

Currently I am struggling with finding the best approach, to implement the following, maybe not everyday, requirement.

I plan to develop a Laravel application. The very general idea of this application is to generate the for websites, which are based on Laravel too, but completely working independent. So as an example: I, as an user, login to the Laravel application, create a new record „Webseite“ in the database and have, let’s say about 50 settings to individualize the website. To have some example of settings, this could be: the logo on the website, decision if the website should have a blog or not, the theme color to used in bootstrap variables, etc. After I have configured the website, I press a button and the Laravel application generates the code for this website, which works on Laravel too. In our case, we are building Statamic websites. So, after this process, I can download a Zip or even better everything gets moved to a new Git repository for this website and in this repository, I have all the files (app, bootstrap, config, content, database, .env.example, etc…) I need to get my Statamic running on any server. Now I have just to clone this new generated repository (or upload the Zip) to any server, run composer install & cp .env.example .env and website is ready to go.

In other words, with this Laravel application I want to write/generate code for another Laravel website. Code in this case means:

  • PHP (configs, routes, …)
  • YAML (Statamic blueprints, ….)
  • Statamic Templates (would prefer to you blade for Statamic instead of Antlers)
  • JS (frontend)
  • SCSS (frontend) And in all these files, I need to use blade-directives as I need to manipulate all these files, depending on the settings of the website.

Without a doubt, it’s technically no problem to do this. To have an config-app-php.blade.php which renders the config/app.php, or to have a app-scss.blade.php, etc.

But for me, it feels wrong to re render PHP, SCSS, JS or even worst, Blade-Template-files from Blade-Template-Files 😄

Do you have any ideas, if there is a better way to implement this?

Thank you very much!

0 likes
3 replies
cptnflx's avatar

I think you completely understand me right as this seems to be definitely the right direction. I general I think the keyword / concept of "Stubs" is the thing I am searching for. Especially in these helper commands to generate models, controllers & co. (artisan make:controller, ...) Laravel seems to do a very similar thing: Generating PHP or other files depending on different parameters.

But Laravel seems to use simple search&replace parameters and variables in the stub-files.

How about logic statements like if and for? Because especially these statements I will need in my stubs. Three examples:

  • load the blog.scss in the app.scss.stub (e.g.) only if $website→blog_activated == true
  • in the layout.blade.stub (e.g.) loop through the footer links ($website→footer_links)
  • in the routes.web.stub create a GET route for each {anything}

In our first MVP (this was Craft CMS, not Statamic) we implemented all these stuff with blade. So, we had files like webpack__mix__js.blade.php, _layout__twig.blade.php, app__scss.blade.php, package__json.blade.php, etc. And yes, it worked, but it was very error-prone because we had to be very careful to escape everything to get no conflict between blade and twig or sass. As we now want to switch to Statamic with Blade as Template-Engine this would get even more problematic.

Is there maybe any "template-engine" or "file-manipulation-library" (or however we can call it) which has a very different syntax from blade, twig, sass, antlers, but offers if, for, etc. too?

Something like ### IF() ###, ### FOR ### or anything else, far away from @if, {}, {{}}, etc.

Thanks!!

jlrdw's avatar

Just use php, it's also a template engine. Blade at runtime has to convert back to php.

Please or to participate in this conversation.