# Template Model | DB Table Name | {wp_db_prefix}_posts | |---------------|-----------------------------------------------------------------| | Schema | Check Schema | | Source File | fluent-crm/app/Models/Template.php | | Name Space | FluentCrm\App\Models | | Class | FluentCrm\App\Models\Template | ## Attributes
Attribute Data Type Comment
ID Integer
post_author Integer
post_date Date Time
post_date_gmt Date Time
post_content Long Text
post_title Text
post_excerpt Text
post_status String
comment_status String
ping_status String
post_name String
post_type String
post_mime_type String
post_date Date Time
post_modified Date Time
## Usage Please check Model Basic for Common methods. ### Accessing Attributes ```php $template = FluentCrm\App\Models\Template::find(1); $template->id; // returns id $template->post_status; // returns post status ....... ``` ## Fillable Attributes ```php 'ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_name', 'post_type', 'post_mime_type', 'post_date', 'post_modified' ``` ## Scopes This model has the following scope that you can use ### emailTemplates($types) returns all email templates by filtering post_status - Parameters - $types - `array` - default ['publish'] #### Usage: ```php $emailTemplates = FluentCrm\App\Models\Template::emailTemplates(['draft', 'publish'])->get(); ``` ### campaignTemplate() returns all email templates by filtering post_status - Parameters - none #### Usage: ```php $campaignTemplate = FluentCrm\App\Models\Template::campaignTemplate()->get(); ``` ## Relations This model has the following relationships that you can use ### campaign Get the campaign of model - returns `FluentCrm\App\Models\Campaign` Model #### Example: ```php // Accessing actions $campaign = $funnel->campaign; ``` // You can also limit your results based on the existence of a relationship. For example, if you want to get all the templates that have ids 1, 2 and 3 in the campaign, you can do the following: ```php // Get Templates which have campaign ids: 1/2 $templates = FluentCrm\App\Models\Template::whereHas('campaign', function($query) { $query->whereIn('id', [1,2]); })->get(); ``` ## Methods Along with Global Model methods, this model has few helper methods. ### render($content) Render the template content - Parameters - $content `string` Default: null - Returns `string` #### Usage ```php $renderedText = $template->render(); ```