timber

Using custom functions with Timber

岁酱吖の 提交于 2020-04-10 06:10:29
问题 I've been trying to get a custom function working by using the example in the Timber starter theme, and following the instructions in the Timber docs, but I can't for the life of me get this working. My functions.php is like so: class StarterSite extends TimberSite { ... function my_function() { return "Foo"; } function add_to_twig( $twig ) { /* this is where you can add your own functions to twig */ $twig->addExtension( new Twig_Extension_StringLoader() ); $twig->addFilter('my_function', new

Using custom functions with Timber

落爺英雄遲暮 提交于 2020-04-10 06:09:59
问题 I've been trying to get a custom function working by using the example in the Timber starter theme, and following the instructions in the Timber docs, but I can't for the life of me get this working. My functions.php is like so: class StarterSite extends TimberSite { ... function my_function() { return "Foo"; } function add_to_twig( $twig ) { /* this is where you can add your own functions to twig */ $twig->addExtension( new Twig_Extension_StringLoader() ); $twig->addFilter('my_function', new

Translate ACF field that renders in twig template

☆樱花仙子☆ 提交于 2020-02-07 02:38:24
问题 I'm working on a site where i in twig renders content that gets set via ACF-fields. Currently i'm implementing translations and was wondering how i would do it since it not really strings, its twig. Php file: $context = Timber::get_context(); $context['header'] = array( 'title' => get_field('header_title') ); Timber::render('/templates/index.twig', $context); My template looks like this. <header> {% if header.title %} <h1> {{ header.title }} </h1> {% endif %} </header> But for the translation

Custom Twig Function Not Recognized

China☆狼群 提交于 2020-01-15 08:51:30
问题 I have a twig/timber function and the code doesn't shows any error but when I go to use function in my twig template there is an error saying '' is not a function. This is what I have in my fucntions.php file in the twig template: add_filter( 'timber/twig', function( \Twig_Environment $twig ) { $twig->addFunction( new Twig_Function( 'get_custom_meta', 'get_custom_meta' ) ); } ); function get_custom_meta($key,$id){ if(empty($id)){ return types_render_field($key,array("raw"=>"true","separator"=

Excluding Categories

拟墨画扇 提交于 2019-12-24 08:22:56
问题 Currently I'm listing all post categories but I'm hoping to exclude certain categories that exist e.g. Uncategorised. This is how I'm initiating categories at the moment: $context['categories'] = Timber::get_terms('category'); and listing the categories via {% for cat in categories %} <li><a style="margin: 0;" href="{{cat.link}}">{{cat.name}}</a></li> {% endfor %} 回答1: You have several possibilities. Here are two: 1. Exclude in Query When using Timber::get_terms() or Timber::get_posts() you

wordpress simple shortcodes not rendered when using Timber plugin

五迷三道 提交于 2019-12-24 06:45:43
问题 I've recently taken over dev of a Wordpress site using Timber (which I wasn't familiar with). I'm attempting to use a new plugin and accompanying shortcode, which of course doesn't work. I've been researching this for a couple hours and there doesn't seem to be a simple answer. In order to use a simple shortcode like this: [sp_faq category="7"] Do I really need to create a custom shortcode function in functions.php, add some sort of template file for it, etc? This seems counterintuitive to

Timber pagination with custom Query gives me 404

旧街凉风 提交于 2019-12-22 01:49:30
问题 I am kinda a newbie at Wordpress. I've looked a lot on StackOverflow for a solution for this problem but none worked for me. I'm using Timber and ACF. Here's the situation: I've made 4 custom post_type ( News, Products, Services and Places ). I've created a custom page for the news. ( page-news.twig ) In my page.php file I've added a custom query like this: global $paged; if (!isset($paged) || !$paged) { $paged = 1; } $context = Timber::get_context(); $post = new TimberPost(); $context['post'

Timber duplicate logs after calling finish() and restarting app

蓝咒 提交于 2019-12-20 03:11:52
问题 I have an onTouchListener on my TextView. On touch, I log with Timber.i() and then I call finish() . If after finish(), I launch my app again, and click again on the TextView, It will log twice, then 3 times, etc... (If I replace Timber.i() by the normal Log.i(), there is no problem) // first time Clicked // second time Clicked Clicked // etc... Clicked Clicked Clicked Timber version : compile 'com.jakewharton.timber:timber:4.5.1' Working code : public class MainActivity extends

Divide datas into 2 columns list using Twig

﹥>﹥吖頭↗ 提交于 2019-12-13 03:47:07
问题 I'm trying to divide datas into 2 columns. I would like to have a structure like this : <div class="accordion"> <div class="accordion__list"> <div class="accordion__item"> <p class="accordion__text">Title</p> <div class="accordion__content"> <p>Content</p> </div> </div> <div class="accordion__item"> <p class="accordion__text">Title</p> <div class="accordion__content"> <p>Content</p> </div> </div> </div> <div class="accordion__list"> <div class="accordion__item"> <p class="accordion__text"

Sorting a repeater field from Advanced Custom Fields in PHP and Timber/Twig

。_饼干妹妹 提交于 2019-12-12 14:17:14
问题 I'm trying to sort the output of a repeater field from the WordPress plugin Advanced Custom Fields (ACF) using the WordPress Timber plugin implementation of Twig 1.34. The basic PHP example to sort from ACF below is from https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/ and there are no usable answers for my question in the ACF forums. So I'm trying to convert this function from the example to Timber/Twig: // get repeater field data $repeater = get_field(