Hi guys,
I am trying to create new templates for the site, but the steps repeat itself a lot, so I create a bash shell in Unix to reduce the creation time.
First, I need to create a new file named: create-new-template
Then add the permission for the file
chmod 755 create-new-template
Then I added the commands to the file.
#!/bin/bash
echo 'Creating new template:' $1
cp resources/views/template-custom.blade.php resources/views/template-$1.blade.php
mkdir resources/views/pages/$1
touch resources/views/pages/$1/content-$1.blade.php
cp app/controllers/app.php app/controllers/template-$1.php
Now, every time I want to create a new template, I just need to run the file at the root of the theme.
./create-new-template template-name
After that, you just need to edit the content of those files to make it work.
Hope this help
3 Likes
Wouldn’t it be easier to create a snippet in your editor of choice? It’s really easy in Visual Studio code, and you insert variables.
Here’s a sample I use to create a Sage Controller.
{
"sage-controller": {
"prefix": "sage",
"scope": "php",
"body": [
"<?php",
"",
"namespace App;",
"",
"use Sober\\Controller\\Controller;",
"",
"class ${TM_FILENAME_BASE} extends Controller",
"{",
" public function siteName()",
" {",
" return get_bloginfo('name');$1",
" }",
"}"
],
"description" : "Create a Sage Controller",
}
}
4 Likes
Thanks @BeyondLimts99, it’s very convenient for auto-generating the content. Can VS create folders and files automatically? It would be wonderful if it can do it
Anyway, your snippet is great to create the content of the controller. I will take advantage of it
Check out these two VS Code extensions for adding new paths/files:
2 Likes