2

I would like to know what is the equivalent of:

@include('sidebars.pages')

In plain PHP?

I tried such things as:

<?php echo view('sidebars.pages'); ?>
<?php echo view('sidebars.pages')->render(); ?>
<?php echo render('sidebars.pages'); ?>
<?php Blade::compile_string("@include('sidebars.pages')"); ?>

I appreciate any help!

2 Answers 2

2

Literally it's translated in to...

<?php echo $__env->make('sidebar.pages', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

So out of your list of attempts, nearest might be

<?php echo render('sidebar.pages', array_except(get_defined_vars(), array('__data', '__path'))); ?>

Reference: View\Compilers\BladeCompiler

/**
 * Compile Blade include statements into valid PHP.
 *
 * @param  string  $value
 * @return string
 */
protected function compileIncludes($value)
{
    $pattern = $this->createOpenMatcher('include');

    $replace = '$1<?php echo $__env->make$2, array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>';

    return preg_replace($pattern, $replace, $value);
}

/**
 * Get the regular expression for a generic Blade function.
 *
 * @param  string  $function
 * @return string
 */
public function createOpenMatcher($function)
{
    return '/(?<!\w)(\s*)@'.$function.'(\s*\(.*)\)/';
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Mr. Sparks, I was really curious.
0

I know this has already been answered but wouldn't the following also work?

<?php include 'app/views/yourview.php'; ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.