timber

Twig highlight word (Timber plugin)

老子叫甜甜 提交于 2019-12-11 06:14:23
问题 I use Timber plugin for Wordpress. And I create a results search page. I would like to highlight the word that the user searched. In PHP I wrote that : $highlight = array(); if ($terms) { foreach($terms as $term) { array_push($highlight, '<span class="blue bold">'.$term.'</span>'); } } And that, to replace the searched word in PHP : <p class="date red"><?php echo str_ireplace($terms, $highlight, get_field('subtitle_post')); ?></p But I don't know how to transform that in Twig (Timber) ? 回答1:

Timber - extend data to context (WordPress)

久未见 提交于 2019-12-10 11:58:39
问题 So I'm trying to make this functions data available to each context there this, but I'm stuck with how to actually get the data itself now that its part of the context. I have the following: add_filter( 'timber_context', 'fancySquares_get_instagram_images' ); function fancySquares_get_instagram_images( $context ) { $context['instaImages'] = []; $api = wp_remote_request("testUrlHere"); $api = json_decode($api['body']); for($i = 0; $i < 20; $i++) { $images[$i] = []; $images[$i]['image'] = $api-

How to include Retina images in Timber?

江枫思渺然 提交于 2019-12-10 11:56:50
问题 I'd really like to improve my website (built with Timber) for Retina displays and browsed through past issues on GitHub as well as the Docs. So I added a srcset and used the retina filter (which is deprecated?) and that retina resizing works quite well, but not really in conjunction with the standard resize filter. Also, I saw that there's an ImageHelper class which provides a retina_resize function/filter(?), but I'm not quite sure how to use it. This is my code right now: <img srcset="{{

Twig: Can a child template override a block from a file included in the parent template?

半腔热情 提交于 2019-12-08 18:04:25
I have a largish base.twig file, and I want to break it up into three includes: header.twig, content.twig, and footer.twig. I'm having trouble getting the block from my child template to override the block included into my parent template and would like to know if it's even possible, and if not, what a Twig-ish solution might look like. I've setup a simple example to illustrate the question. I'm retrieving a Wordpress page and using Timber to process the Twig templates. The PHP template that gets invoked is page-test.php: <? $context = Timber::get_context(); Timber::render('test_child.twig',

Twig: Can a child template override a block from a file included in the parent template?

我的梦境 提交于 2019-12-08 04:13:18
问题 I have a largish base.twig file, and I want to break it up into three includes: header.twig, content.twig, and footer.twig. I'm having trouble getting the block from my child template to override the block included into my parent template and would like to know if it's even possible, and if not, what a Twig-ish solution might look like. I've setup a simple example to illustrate the question. I'm retrieving a Wordpress page and using Timber to process the Twig templates. The PHP template that

How to parse Timber (twig) templates with poedit and detect quoted strings to translate

强颜欢笑 提交于 2019-12-07 08:12:31
问题 I want to parse twig templates for Timber with poedit and I need to translate quoted contents. The problem is that I can't find a parser that does not skip quoted content. Example: <htmltag attribute="{{ __('value','textdomain') }}" /> Does someone know of a parser for poedit that detects quoted content, like html attribute content? 回答1: The workaround I found is to set a variable and use it as my attribute value. {% set attr_value = __('value', 'textdomain') %} <a href='{{ attr_value }}'

Using custom functions with Timber

删除回忆录丶 提交于 2019-12-04 21:07:42
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 Twig_SimpleFilter('my_function', array($this, 'my_function'))); return $twig; } } Then my Twig file:

Twig_Error_Syntax for “Unknown filter” with a Twig filter in Timber

倖福魔咒の 提交于 2019-12-04 04:05:44
问题 This has got to be simple, but I can't see what's wrong. I'm using the simple filter example at https://twig.symfony.com/doc/1.x/advanced.html#filters with Twig 1.34 in Timber, a WordPress plugin. I added // an anonymous function $filter = new Twig_SimpleFilter('rot13', function ($string) { return str_rot13($string); }); and $twig = new Twig_Environment($loader); $twig->addFilter($filter); to my theme's functions.php file. But using {{ 'Twig'|rot13 }} in my view.twig file gives a fatal error

Android Timber ѧϰ

匿名 (未验证) 提交于 2019-12-03 00:22:01
1.AS中添加依赖项 implementation " com .jakewharton .timber :timber :4 .5 .1 " 2.OnCreate中注册 if (BuildConfig.DEBUG) { Timber.plant( new Timber.DebugTree()); } else { Timber.plant( new CrashReportingTree()); } 添加类 private static class CrashReportingTree extends Timber . Tree { @Override protected void log ( int priority, String tag, String message, Throwable t) { } } 3.使用过程 Timber .tag ( "activityName" ) ; Timber .e ( "Activity Created" ) ; 参考文章: 1. https://blog.csdn.net/u011376022/article/details/60575632 2. https://www.jianshu.com/p/4f54fcba3ad3 文章来源: Android Timber ѧϰ

Displaying Wordpress custom post type by first letter with Timber (twig)

纵然是瞬间 提交于 2019-12-02 22:14:54
问题 I use Timber for Wordpress and I would like to create a dictionary system like that : https://wordpress.stackexchange.com/questions/119163/displaying-custom-post-type-by-first-letter-through-custom-taxonomy I wrote this : lexique.php $query = get_posts(array('post_type' => 'lexique','posts_per_page' => -1)); But I don't know how to transform this with Timber : $by_letter = array(); while( $query->have_posts() ) { $query->the_post(); global $post; $letter = substr($post->post_name, 0, 1); if (