{"id":23638,"date":"2013-05-30T12:51:26","date_gmt":"2013-05-30T12:51:26","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/twigpress\/"},"modified":"2015-02-22T21:31:20","modified_gmt":"2015-02-22T21:31:20","slug":"twigpress","status":"publish","type":"plugin","link":"https:\/\/twd.wordpress.org\/plugins\/twigpress\/","author":10380741,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.1.2","stable_tag":"1.1.2","tested":"4.1.42","requires":"4.1","requires_php":"","requires_plugins":"","header_name":"TwigPress","header_author":"Mike Shaw","header_description":"","assets_banners_color":"","last_updated":"2015-02-22 21:31:20","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"","rating":5,"author_block_rating":0,"active_installs":20,"downloads":3863,"num_ratings":2,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"2"},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.1.0","1.1.1","1.1.2"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[4516,1249,17808],"plugin_category":[43],"plugin_contributors":[92426],"plugin_business_model":[],"class_list":["post-23638","plugin","type-plugin","status-publish","hentry","plugin_tags-templates","plugin_tags-themes","plugin_tags-twig","plugin_category-customization","plugin_contributors-mikeshaw217","plugin_committers-mikeshaw217"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/twigpress.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin provides a simple way for you to use the <a href=\"http:\/\/twig.sensiolabs.org\/\">Twig templating engine<\/a> with <a href=\"http:\/\/wordpress.org\/\">WordPress<\/a> 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 <a href=\"http:\/\/twig.sensiolabs.org\/\">Twig templating engine<\/a> is a great engine that allows you to separate out getting &amp; 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.<\/p>\n\n<p>The Installation section provides the steps to using this plugin with your theme.<\/p>\n\n<p>In the Other Notes section, there is an easy reference for the different functions\/filters and what they can be used for.<\/p>\n\n<p>For Twig, the <a href=\"http:\/\/twig.sensiolabs.org\/documentation\">Twig documentation<\/a> is the best resource I can offer. It is extremely well documented.<\/p>\n\n<h3>Functions and Filters<\/h3>\n\n<p><br \/><\/p>\n\n<h4>Functions<\/h4>\n\n<p><br \/><\/p>\n\n<pre><code>twigpress_render_twig_template($vals = array(), $template = false, $echo = true)\n<\/code><\/pre>\n\n<p>Calling this function renders a <code>$template<\/code> with the values passed in <code>$vals<\/code>. You can also choose a specific template to render and whether you would like to echo the template or simply return it.<\/p>\n\n<p>There is no need to explicitly set the <code>$template<\/code> 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 <code>front-page.php<\/code> is being rendered the plugin will attempt to find <code>front-page.twig<\/code>.<\/p>\n\n<p>If you wish to simply return the rendered template, set <code>$echo<\/code> to <code>false<\/code>.<\/p>\n\n<p><br \/><\/p>\n\n<pre><code>twigpress_get_the_content()\n<\/code><\/pre>\n\n<p>Use this function to get the content for the post you are dealing with. If you use <code>get_the_content<\/code>, WordPress returns the unformatted content and the <code>the_content<\/code> filter is not applied. <code>twigpress_get_the_content()<\/code> takes care of both of these tasks.<\/p>\n\n<p><br \/><\/p>\n\n<h4>Filters<\/h4>\n\n<p><br \/><\/p>\n\n<pre><code>twigpress_twig_site_variables\n<\/code><\/pre>\n\n<p>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 <code>twigpress_twig_post_template_vars<\/code> filter.<\/p>\n\n<p>Defaults:<\/p>\n\n<pre><code>'site' =&gt; array(\n    'lang_attributes' =&gt; get_bloginfo('language'),\n    'charset' =&gt; get_bloginfo('charset'),\n    'url' =&gt; get_bloginfo('url'),\n    'stylesheet_directory' =&gt; get_stylesheet_directory_uri(),\n    'title' =&gt; get_bloginfo('name'),\n    'description' =&gt; get_bloginfo('description')\n)\n<\/code><\/pre>\n\n<p>In templates these would be accessible through, for example, <code>{{ site.stylesheet_directory }}<\/code>.<\/p>\n\n<p><br \/><\/p>\n\n<pre><code>twigpress_twig_global_functions\n<\/code><\/pre>\n\n<p>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.<\/p>\n\n<p>Defaults: <code>wp_head()<\/code>, <code>wp_footer()<\/code>, <code>wp_title()<\/code>, <code>body_class()<\/code>, <code>wp_nav_menu()<\/code><\/p>\n\n<p><br \/><\/p>\n\n<pre><code>twigpress_twig_post_template_vars\n<\/code><\/pre>\n\n<p>This filter is applied to your passed array of <code>$vars<\/code> 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.<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Download the plugin from WordPress, either directly or through the plugins admin screen\n    - If you download the files directly, upload them to your <code>\/wp-content\/plugins\/<\/code> directory<\/li>\n<li>Place the Twig files in your <code>wp-content<\/code> directory, <code>Autoloader.php<\/code> should reside at <code>wp-content\/Twig\/Autoloader.php<\/code><\/li>\n<li>Create a 'twigs' directory inside your theme folder, place your Twig templates in here<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress<\/li>\n<li>Use the <code>twigpress_render_twig_template()<\/code> function in your PHP files to render templates<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<h4>1.1.2<\/h4>\n\n<ul>\n<li>[Added] If WP_DEBUG is enabled, turn on debugging in the Twig environment<\/li>\n<\/ul>\n\n<h4>1.1.1<\/h4>\n\n<ul>\n<li>Strict variables are no longer enforced<\/li>\n<\/ul>\n\n<h4>1.1.0<\/h4>\n\n<ul>\n<li>[Added] TwigPress now sets up a template cache in your theme folder<\/li>\n<li>[Added] TwigPress sets the Twig core to recompile templates when the source code changes<\/li>\n<li>[Added] TwigPress sets the Twig core to enforce strict variables, which stops silent failure<\/li>\n<\/ul>\n\n<h4>1.0.1<\/h4>\n\n<ul>\n<li>Minor changes to codebase<\/li>\n<\/ul>\n\n<h4>1.0.0<\/h4>\n\n<ul>\n<li>Initial release<\/li>\n<\/ul>","raw_excerpt":"This plugin provides a simple way for you to use the Twig templating system within WordPress themes.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/23638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=23638"}],"author":[{"embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/mikeshaw217"}],"wp:attachment":[{"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=23638"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=23638"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=23638"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=23638"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=23638"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/twd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=23638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}