前言介紹
- 這款 WordPress 外掛「TwigPress」是 2013-05-29 上架。
- 目前有 30 個安裝啟用數。
- 上一次更新是 2015-02-22,距離現在已有 3723 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 4.1 以上版本才可以安裝。
- 有 2 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
內容簡介
本外掛可為你提供使用Twig模板引擎與WordPress主題的簡便方法。WordPress主題的一個問題是創建混合了PHP和HTML的模板非常容易。這對工作不好,也沒有關注分離。Twig模板引擎是一個優秀的引擎,可以將取得和操作數據和渲染數據分離出來。你可以像以前一樣建立你的主題,只需渲染模板而不是在頁面結構中使用PHP。
安裝部分提供了使用此外掛與你的主題的步驟。其他注釋中有一個簡單的參考,列出了不同的函數/過濾器及其用途。
對於Twig,我可以提供的最佳資源是Twig文件,它有極好的文檔。
功能和過濾器:
功能:
- `twigpress_render_twig_template($vals = array(), $template = false, $echo = true)`:調用此功能使用傳遞給`$vals`的值來渲染`$template`。你還可以選擇要渲染的特定模板,以及是否要回傳模板或僅簡單地返回它。不需要明確設置`$template`名稱。如果使用默認值,外掛將尋找與正在渲染的PHP文件同名的模板(使用`.twig`擴展名)。例如,如果渲染的是`front-page.php`,該外掛將嘗試尋找`front-page.twig`。如果你希望僅返回渲染後的模板,將`$echo`設置為`false`。
- `twigpress_get_the_content()`:使用此功能獲取你正在處理的文章內容。如果使用`get_the_content`,WordPress會返回未格式化的內容,也不應用`the_content`過濾器。`twigpress_get_the_content()`會處理這兩個任務。
過濾器:
- `twigpress_twig_site_variables`:在外掛實例化時應用此過濾器,在`init`操作上,允許你修改在創建Twig環境時傳遞的變數數組。因此,這些變數對所有模板都可用。該過濾器最適合用於網站範圍信息。對於特定於文章的變數,請使用`twigpress_twig_post_template_vars`過濾器。
- `twigpress_twig_global_functions`:有時你需要在模板中使用PHP函數,並且沒有辦法捕獲它們的內容以在渲染模板時傳遞。此過濾器使你可以訪問添加到Twig環境中的功能數組,從而可以在模板中調用它們。
原文外掛簡介
This plugin provides a simple way for you to use the Twig templating engine with WordPress themes. A problem with WordPress themes is that it is very easy to create templates that are a mess of PHP and HTML. This isn’t good for working with neither does it provide a separation of concerns. The Twig templating engine is a great engine that allows you to separate out getting & manipulating your data and rendering it out. You create your themes in the same way as before, only you render a template instead of using PHP within your page structure.
The Installation section provides the steps to using this plugin with your theme.
In the Other Notes section, there is an easy reference for the different functions/filters and what they can be used for.
For Twig, the Twig documentation is the best resource I can offer. It is extremely well documented.
Functions and Filters
Functions
twigpress_render_twig_template($vals = array(), $template = false, $echo = true)
Calling this function renders a $template with the values passed in $vals. You can also choose a specific template to render and whether you would like to echo the template or simply return it.
There is no need to explicitly set the $template name. If this is left to the default, the plugin will look for a template with the same name as the PHP file being rendered (with a ‘.twig’ extension). For example, if front-page.php is being rendered the plugin will attempt to find front-page.twig.
If you wish to simply return the rendered template, set $echo to false.
twigpress_get_the_content()
Use this function to get the content for the post you are dealing with. If you use get_the_content, WordPress returns the unformatted content and the the_content filter is not applied. twigpress_get_the_content() takes care of both of these tasks.
Filters
twigpress_twig_site_variables
This filter is applied when the plugin is instantiated, on the ‘init’ action, and allows you to alter the array of variables that are passed to the Twig environment when it is first created. As such, these variables are available to all templates. This filter is best suited for site-wide information. For post-specific variables, use the twigpress_twig_post_template_vars filter.
Defaults:
'site' => array(
'lang_attributes' => get_bloginfo('language'),
'charset' => get_bloginfo('charset'),
'url' => get_bloginfo('url'),
'stylesheet_directory' => get_stylesheet_directory_uri(),
'title' => get_bloginfo('name'),
'description' => get_bloginfo('description')
)
In templates these would be accessible through, for example, {{ site.stylesheet_directory }}.
twigpress_twig_global_functions
There will be times when you need to use PHP functions in your templates, and there is no way to capture their content to pass to the template when it is rendered. This filter gives you access to the array of functions that are added to the Twig environment, making them available for calling in your templates.
Defaults: wp_head(), wp_footer(), wp_title(), body_class(), wp_nav_menu()
twigpress_twig_post_template_vars
This filter is applied to your passed array of $vars immediately before the template is rendered. This filter is ideal for when you have a set of default variables you wish to include in every template, but are related to posts not the entire site.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「TwigPress」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
1.1.0 | 1.1.1 | 1.1.2 | trunk |
延伸相關外掛(你可能也想知道)
YITH WooCommerce Catalog Mode 》H WooCommerce Catalog Mode外掛描述:, , 您是否有興趣展示產品或服務目錄,但暫時不希望讓它們立即上架出售?, 您是否正在進行盤點,但仍希望將產品保留在...。
Theme Check 》主題檢查外掛是測試您的佈景主題並確保其符合最新 主題審查 標準的一種簡單方法。透過此外掛,您可以運行 WordPress.org 用於主題提交的所有自動化測試工具。...。
Advanced Automatic Updates 》Advanced Automatic Updates 為 WordPress 內建的自動更新功能添加了額外的選項。除了安全更新外,它還支持安裝重大版本、外掛、主題甚至是定期的 SVN 檢出!...。
Theme Authenticity Checker (TAC) 》掃描所有主題文件,尋找潛在的惡意或不需要的程式碼。, TAC 是什麼, TAC 代表主題真實性檢查器。TAC 搜尋每個安裝主題的原始檔案,尋找惡意程式碼的跡象。如...。
SKT Templates – 100% free Elementor & Gutenberg templates 》, SKT Templates 是一個可以在 Elementor 和 Gutenberg 主題庫中挑選超過上百款模板的外掛,只需要瀏覽 Demo 畫面,挑選適合的模板後點擊匯入並安裝即可。它...。
Multiple Themes 》重要提示:支援服務已移至 ZATZLabs 網站,不再於 WordPress.org 論壇提供。如需開發者迅速回覆,請提交請求單。, 此外掛設定提供多種選擇方式,可讓您選擇要...。
Demo Importer Plus 》Demo Importer Plus 是最佳和強大的演示內容導入外掛之一。它允許您輕鬆地通過單擊一個按鈕來導入演示內容、小工具、定制器設置以及主題設置。, 除此之外,您...。
Hello Plus 》**總結:**, Hello+ 是一個免費的 WordPress 外掛,專為與 Elementor 的 Hello Themes(例如 Hello Biz)無縫合作而設計。它提供了堅固的基礎,讓使用者可以...。
WP-LESS 》LESS 是一種基於 CSS 的樣板語言。它提供了許多增強功能,以加速開發並使維護更容易。, 主題開發人員甚至可以捆綁該外掛而不用擔心衝突:只需包含特殊的 boot...。
Create Block Theme 》此外掛讓您可以:, – 建立新主題、空白主題、子主題或風格變化。, – 列出並預覽嵌入您佈景中的字型家族和字型樣式。, – 嵌入 Google...。
Theme Test Drive 》Theme Test Drive WordPress外掛程式允許您以管理員身份安全地在您的部落格上測試任何佈景主題,而訪客仍然使用預設佈景主題。, 這樣做是完全透明的,他們甚...。
Child Themify 》使用一個按鈕從任何非子佈景主題建立子佈景主題。, 此外掛程式支援多站點,若在多站點網路中使用,在網路管理員中會顯示建立子佈景主題的選項控制項,而非一...。
WP Theme Test 》該外掛可讓僅登入的使用者更改和顯示主題。, 當您測試新主題時,網站訪客則會看到您的舊主題。, 僅 WordPress 網站管理員可以安全地看到新主題並進行測試。, ...。
YITH Custom Login 》安裝這個外掛,改變 WordPress 登入的預設風格。為您的網站登入頁面設置漂亮的風格,並根據您的風格進行自定義!, 完整的文檔在這裡提供。, 安裝, 一旦您安裝...。
Export Themes 》這個外掛讓你能夠將主題以 .zip 檔案匯出,然後利用 WordPress 的「上傳」功能,在其他伺服器上安裝相同的主題。, 使用方式, 安裝完外掛後,你需要進入「外觀...。