我是编写WordPress插件的新手.我正在尝试编写一个小插件来修改woocommerce插件如何在单个产品页面上显示图像.具体来说,如果没有产品图像,请使div保持图像"display:none",而不是在那里显示占位符图像.我正在使用的策略是使用add_action来渲染我自己的woocommerce的product_image.php模板版本,然后(尝试)使用remove_action来防止渲染原始的product_image.php文件.add_action显然正常工作,因为我可以在Firebug中看到"display:none"div.但是,remove_action没有成功.
这是我的代码:
$add_result = add_action( 'woocommerce_before_single_product_summary', 'eba_wc_show_product_images', 10);
function eba_wc_show_product_images() {
include( 'eba_product-image.php' );
}
$remove_result = remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 30);
echo "<hr/>result of add_result = " . $add_result . "<hr/>";
echo "<hr/>result of remove_result = " . $remove_result . "<hr/>";
Run Code Online (Sandbox Code Playgroud)
woocommerce_before_single_product_summary钩子的原始add_action的优先级是20,所以我在remove_action 30上做了优先级.
最后的两个调试语句显示add_action返回"1",但remove_action的结果为空.任何帮助将不胜感激.
我有一个base.html.twig模板,我已成功扩展到index.html.twig文件中,我认为这意味着base.html.twig文件格式正确且被正确调用(这是我的第二天Symfony,请耐心等待.)我成功安装了APYDataGridBundle,并且能够在其他空模板中显示网格:
{{ grid(grid) }}
Run Code Online (Sandbox Code Playgroud)
但是当我在index.html.twig中扩展base.html.twig时,我收到一个错误.代码:
{% extends '::base.html.twig' %}
{{ grid(grid) }}
Run Code Online (Sandbox Code Playgroud)
导致此错误:扩展另一个模板的模板不能在TestTranspoBundle中具有正文:程序:第2行的index.html.twig.
我在APYDataGridBundle问题中没有看到任何相关内容,如果它是他们的错误而不是我的用户错误,这似乎是一个大问题.所以我希望我只是犯了一个新手错误.
这是调用模板的控制器:
namespace Test\TranspoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use APY\DataGridBundle\Grid\Source\Entity;
class ProgramsController extends Controller
{
public function indexAction()
{
$source = new Entity('TestTranspoBundle:Programs');
$grid = $this->get('grid');
$grid->setSource($source);
$grid->isReadyForRedirect();
return $this->render('TestTranspoBundle:Programs:index.html.twig', array('grid' => $grid));
}
}
Run Code Online (Sandbox Code Playgroud)
这是base.html.twig:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{% block title %}My System - Symfony{% endblock %}</title>
{% block stylesheets %}
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/testtranspo/css/screen.css') }}" …Run Code Online (Sandbox Code Playgroud)