本文整理汇总了PHP中Blade::getCompiler方法的典型用法代码示例。如果您正苦于以下问题:PHP Blade::getCompiler方法的具体用法?PHP Blade::getCompiler怎么用?PHP Blade::getCompiler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blade
的用法示例。
在下文中一共展示了Blade::getCompiler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extend
/**
* Extend blade
* @return void
*/
protected function extend()
{
// add @acfrepeater
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@acf\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( have_rows( $2 ) ) : ';
$replacement .= 'while ( have_rows( $2 ) ) : the_row(); ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @acfempty
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@acfempty', '<?php endwhile; ?><?php else: ?>', $view);
});
// add @acfend
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
return str_replace('@acfend', '<?php endif; ?>', $view);
});
// add @subfield
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@subfield\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( get_sub_field( $2 ) ) : ';
$replacement .= 'the_sub_field($2); endif; ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @field
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@field\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( get_field( $2 ) ) : ';
$replacement .= 'the_field($2); endif; ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @hasfield
$this->blade->getCompiler()->extend(function ($view, $compiler) {
if (!function_exists('get_field')) {
return $view;
}
$pattern = '/(\\s*)@hasfield\\(((\\s*)(.+))\\)/';
$replacement = '$1<?php if ( get_field( $2 ) ) : ?>';
return preg_replace($pattern, $replacement, $view);
});
// add @wpposts
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@wpposts', '<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>', $view);
});
// add @wpquery
$this->blade->getCompiler()->extend(function ($view, $compiler) {
$pattern = '/(\\s*)@wpquery(\\s*\\(.*\\))/';
$replacement = '$1<?php $bladequery = new WP_Query$2; ';
$replacement .= 'if ( $bladequery->have_posts() ) : ';
$replacement .= 'while ( $bladequery->have_posts() ) : ';
$replacement .= '$bladequery->the_post(); ?> ';
return preg_replace($pattern, $replacement, $view);
});
// add @wpempty
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@wpempty', '<?php endwhile; ?><?php else: ?>', $view);
});
// add @wpend
$this->blade->getCompiler()->extend(function ($view, $compiler) {
return str_replace('@wpend', '<?php endif; wp_reset_postdata(); ?>', $view);
});
// add @scripts
$self = $this;
$this->blade->getCompiler()->directive('scripts', function ($expression) use($self) {
return '<?php ' . get_class($self) . '::add_scripts(' . $expression . '); ?>';
});
}