簡體   English   中英

檢查木材中是否存在 twig 模板

[英]check existence of twig template in Timber

Timber 中是否有辦法在嘗試渲染模板之前檢查 Twig 模板是否存在?

我已經在 Symfony ( $this->get('twig')->getLoader()->exists('AcmeDemoBundle:Foo:bar.html.twig')中看到了有關如何完成此任務的 SO 答案,但我需要一個木材特定的答案。

如果沒有,我總是可以使用特定於 PHP 的

if ( get_stylesheet_directory() . '/templates/template-name.twig' ) { ... }

但我想我會看看是否有人知道實現這一目標的木材方法。

$loader = new Timber\Loader;
if ( $loader->get_loader()->exists( 'template-name.twig' ) ) {
    // file exists
}

感謝@Jeto 提供的線索。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM