When creating a new project you have the option to start from scratch or to select a template. These premade templates allow you to create massiv amount of code with one single click. You can add custom templates yourself using the filter snipr_premade_projects.

premade_templates_arrow

This example adds a new template called “my_project“. It will add one PHP file with a custom code editor (speedy coder) item attached.

<?php 
/**
 * Using the "snipr_premade_projects" filter.
 *
 * $projects (array) All available project templates.
 * $key (string) (dafault = '') The selected project template key name.
 * $args (array) The project template arguments.
 */
add_filter('snipr_premade_projects', 'my_project_templates', 10, 3);
function my_project_templates( $projects, $key, $args ){
	
    $my_projects = array(
        'my_project' => array(
        	/**
        	 * Code: Load the item code. 4 arguments
        	 * 
        	 * 1. the items array name/key. (in this case: 'my_project')
        	 * 2. the current key ($key)
        	 * 3. the function containing the item vscode. The vscode creates the actual files
        	 * 4. the arguments ($args)
        	 */
            'code' => sniprApi::get_item_code('my_project', $key, 'my_project_vscode', $args),
            'button_title' => __('My Project','snipr'),
            'btn_icon' => '/images/my_project.png',
            'edit_arr' => array(
				'code' => array(
					'type' => 'code_editor',
					'args' => array(
						'label' => __('Speedy Coder','snipr'),
						'desc' => __('Custom code editor.','snipr'),
						'importance' => ''
					),
					'fields' => array(
						'value' => ''
					)
				)
			)
        )
    );
    
    return sniprApi::add_to_array($my_projects, $projects);
}


/**
 * My Project Code
 *
 * $args (array) The project template arguments.
 */
function my_project_vscode( $args ){
    
    // Receive the edit template values.
    $tpl_values = sniprApi::parse_tpl_values($args);
    
    $project_files = array(
    	array(
            'file' => 'my_project.php', 
            'icon' => 'php-file',
            'data' => array(
                'vs_code' => sniprApi::premade_tpl_vscode( 
					array(
						sniprApi::use_code_item(array(
							'index' => 1,
							'editor_id' => sniprApi::editor_id($args['editor_id']),
							'item' => 'code_editor',
							'data' => array(
								'code' => sniprApi::encode($tpl_values['code'])
							)
						))
					)
                )
            ),
            'type' => 'php'
        )
    );
    
    return sniprApi::create_tpl_file_code($project_files);
}