Using Bash Shell to create new template

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.


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 :slight_smile:


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": [
			"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",

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 :slight_smile:

Anyway, your snippet is great to create the content of the controller. I will take advantage of it :smile:

Check out these two VS Code extensions for adding new paths/files:


Thanks @runofthemill :slight_smile:

1 Like