2 added 127 characters in body
source | link

I have wrestled with this before and my solution was — it can knock itself out requiring file, as long as it doesn't do anything.

Here is relevant code from my Meadow templating project:

public function comments_template( \Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false ) {

    try {
        $env->loadTemplate( $file );
    } catch ( \Twig_Error_Loader $e ) {
        ob_start();
        comments_template( '/comments.php', $separate_comments );
        return ob_get_clean();
    }

    add_filter( 'comments_template', array( $this, 'return_blank_template' ) );
    comments_template( '/comments.php', $separate_comments );
    remove_filter( 'comments_template', array( $this, 'return_blank_template' ) );

    return twig_include( $env, $context, $file );
}

public function return_blank_template() {

    return __DIR__ . '/blank.php';
}

I let comments_template() go through the motions to set up globals and such, but feed it empty PHP file to require and move on to my actual Twig template for output.

Note that this requires to be able to intercept initial comments_template() call, which I can do since my Twig template is calling intermediary abstraction rather than actual PHP function.

While I still have to ship empty file for it, I do so in library and implementing theme doesn't have to care about it at all.

I have wrestled with this before and my solution was — it can knock itself out requiring file, as long as it doesn't do anything.

Here is relevant code from my Meadow templating project:

public function comments_template( \Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false ) {

    try {
        $env->loadTemplate( $file );
    } catch ( \Twig_Error_Loader $e ) {
        ob_start();
        comments_template( '/comments.php', $separate_comments );
        return ob_get_clean();
    }

    add_filter( 'comments_template', array( $this, 'return_blank_template' ) );
    comments_template( '/comments.php', $separate_comments );
    remove_filter( 'comments_template', array( $this, 'return_blank_template' ) );

    return twig_include( $env, $context, $file );
}

public function return_blank_template() {

    return __DIR__ . '/blank.php';
}

I let comments_template() go through the motions to set up globals and such, but feed it empty PHP file to require and move on to my actual Twig template for output.

Note that this requires to be able to intercept initial comments_template() call, which I can do since my Twig template is calling intermediary abstraction rather than actual PHP function.

I have wrestled with this before and my solution was — it can knock itself out requiring file, as long as it doesn't do anything.

Here is relevant code from my Meadow templating project:

public function comments_template( \Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false ) {

    try {
        $env->loadTemplate( $file );
    } catch ( \Twig_Error_Loader $e ) {
        ob_start();
        comments_template( '/comments.php', $separate_comments );
        return ob_get_clean();
    }

    add_filter( 'comments_template', array( $this, 'return_blank_template' ) );
    comments_template( '/comments.php', $separate_comments );
    remove_filter( 'comments_template', array( $this, 'return_blank_template' ) );

    return twig_include( $env, $context, $file );
}

public function return_blank_template() {

    return __DIR__ . '/blank.php';
}

I let comments_template() go through the motions to set up globals and such, but feed it empty PHP file to require and move on to my actual Twig template for output.

Note that this requires to be able to intercept initial comments_template() call, which I can do since my Twig template is calling intermediary abstraction rather than actual PHP function.

While I still have to ship empty file for it, I do so in library and implementing theme doesn't have to care about it at all.

1
source | link

I have wrestled with this before and my solution was — it can knock itself out requiring file, as long as it doesn't do anything.

Here is relevant code from my Meadow templating project:

public function comments_template( \Twig_Environment $env, $context, $file = 'comments.twig', $separate_comments = false ) {

    try {
        $env->loadTemplate( $file );
    } catch ( \Twig_Error_Loader $e ) {
        ob_start();
        comments_template( '/comments.php', $separate_comments );
        return ob_get_clean();
    }

    add_filter( 'comments_template', array( $this, 'return_blank_template' ) );
    comments_template( '/comments.php', $separate_comments );
    remove_filter( 'comments_template', array( $this, 'return_blank_template' ) );

    return twig_include( $env, $context, $file );
}

public function return_blank_template() {

    return __DIR__ . '/blank.php';
}

I let comments_template() go through the motions to set up globals and such, but feed it empty PHP file to require and move on to my actual Twig template for output.

Note that this requires to be able to intercept initial comments_template() call, which I can do since my Twig template is calling intermediary abstraction rather than actual PHP function.