ExpressionEngine Notes
Template
| 1 2 3 4 5 6 7 | // p.s. embed 無法用 Variable 傳入值. {embed="path/template"} // 若要用 Variable 可以改採 Snippet 的方式 // 定義 {layout} -> embed="path/template" // 使用: {{layout}} | 
取得 channel 的文章, 並顯示 channel custom field 值
| 1 2 3 4 5 6 7 8 | {exp:channel:entries channel="events" limit="10"}     {channel_custom_field}     // 每一次迴圈會使 absolute_count + 1     {absolute_count} {/exp:channel:entries} | 
if tag
| 1 2 3 4 5 | {exp:beyond:var_set var='testVar' value='Test123'} {if '{exp:beyond:var_get var='testVar'}' == 'Test123'}     if checked! {/if} | 
Custom Tags
編寫 Plugin file:
假設我們今天要建立的 Plugin 名稱叫作 Custom
先在 third_party 資料夾底下建立 custom 資料夾 命名為 pi.custom.php .
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // plugin infomation for CP $plugin_info = array(     'pi_name'           => 'Custom Plugin',     'pi_version'        => '1.0',     'pi_author'         => 'Starck Lin',     'pi_author_url'     => 'http://beyond.com.tw/',     'pi_description'    => 'this is a plugin for demo',     'pi_usage'          =>  Custom::usage() ); Class Custom {     function __construct() {         $this->EE =& get_instance();     }     // Single Tag     // {exp:custom:single_line_tag key='key' value='value'}     //     // result: 'key : value'     function single_line_tag() {         $key = $this->EE->TMPL->fetch_para('key');         $value = $this->EE->TMPL->fetch_para('value');         return $key.' : '.$value;     }     // Tag Block     // {exp:custom:block_tag}     //   Here is block content: {custom_var}     // {/exp:custom:block_tag}     //     // result: 'Here is block content: This is custom value'     //     function block_tag() {         $vars[] = array(             'custom_var' => 'This is custom value'         );         $block_content = $this->EE->TMPL->tagdata;         return $this->EE->TMPL->parse_variables($block_content, $vars);     } } | 
若發現無法使用 $this->EE->TMPL 時
$this->EE->load->library('template',null,'TMPL');
使用 Template::parse_variables_row
| 1 2 3 4 | $this->EE->TMPL->tagdata = '{path="template/test"}'; $vars['path'] = array('', array('path_variable' => TRUE)); return $this->EE->TMPL->parse_variables_row( $this->EE->TMPL->tagdata, $vars ); | 
使用 Template::parse_variables
| 1 2 3 4 5 | $this->EE->TMPL->tagdata = '{path="template/test"}'; $vars[] = array(     'path' => array('', array('path_variable' => TRUE)) ); return $this->EE->TMPL->parse_variables( $this->EE->TMPL->tagdata, $vars ); | 
Module
- upd.module_name.php
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // 安裝 module 時被呼叫的 method function __construct() {     $this->EE =& get_instance(); } function install() {     $data = [         'module_name' => 'Beyond',         'module_version' => $this->version,         'has_cp_backend' => 'y',         'has_publish_fields' => 'y',         'settings' => ''     ];     $this->EE->db->insert('modules', $data);     // return TRUE or FALSE     return TRUE: } // 解除安裝 module 時被呼叫的 method function uninstall() {     $this->EE->db->where('module_name', 'Beyond')->delete('modules');     // return TRUE or FALSE     return TRUE; } | 
- mcp.module_name.php
mcp 就是 module 的 controller, 假設一個被請求的 url 如下:
admin.php?D=cp&C=addons_modules&M=show_module_cp&module=beyond&method=
C=addons_modules 代表目前的 Controller 是 expression/controllers/cp/addons_modules.php M=show_module_cp 代表使用該 controller 的 show_module_cp 這個 method module=beyond 代表被呼叫的 module id名稱為 beyond (third_party/{module_id}) method= 執行該 module controller 的哪一個 method, 未指定預設會導向 index method 
透過指定 method 這個 GET 變數,將改變 module controller 呼叫不同的 method, 另外你也可以外部讀取 template 產生不同的 view, 將這些 templates 放置在 module/views 裡, 透過以下在 module controller 的 method 中回傳:
return $this->EE->load->view('template_name', $vars, TRUE);
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Beyond_mcp {     function __construct() {         $this->EE =& get_instance();         // $this->EE->load('view');     }     // admin.php?D=cp&C=addons_modules&M=show_module_cp&module=beyond&method=     function index() {         return $this->EE->load->view('index', null, TRUE);     } } | 
載入自定義 javascript
| 1 2 3 | // This will load from the current package's javascript director: // /third_party/my_package/javascript/my_file.js $this->EE->cp->load_package_js('my_file'); | 
- mod.module_name.php
- language/english/module_name_lang.php
Language 檔案定義 $lang 語系變數:
語系中
module_name_module_name 和module_name_module_description 會出現在 MCP 的安裝 modules 列表上
| 1 2 3 4 5 6 | $lang = array(     "beyond_module_name"          => 'Beyond Module',     "beyond_module_description"   => '...',  ); | 
How to create or update a Channel Field?
$this->EE->api_channel_fields->update_field((array) $field_data);
returns:
(string) The field_id of the updated/created field.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | $this->EE->load->library('api'); $this->EE->api->instantiate('channel_fields'); $field_data = array(         'group_id' => 1,         'site_id'  => 1,         // $field_id is optional if you are creating a new field         // 'field_id'  => 1,         'field_name' => 'blog_body',         'field_label' => 'Body',         'field_type' => 'text',         'field_order' => 10,         'field_required' => 'y',         'field_search' => 'y',         'field_is_hidden' => 'n',         'field_instructions' => '',         'field_maxl' => 128,         'text_field_fmt' => 'none',         'text_field_show_fmt' => 'n',         'text_field_text_direction' => 'ltr',         'text_field_content_type' => 'all',         'text_field_show_smileys' => 'n',         'text_field_show_glossary' => 'n',         'text_field_show_spellcheck' => 'n',         'text_field_show_file_selector' => 'n',         // and other fieldtype-specific settings, see the fieldtype’s display_settings and save_settings methods for more options ); $this->EE->api_channel_fields->update_field($field_data); |