Laravel - Blade: @include a template with automated "filename-comment" -


i wondering if there way include template in way blade automatically writes html-comment filename @ beginning of included template. helpful in project lots of templates.

example:

// file 1 <div class="bla">   @include('folder.subfolder.templatename') </div>  // file 2 ( folder/subfolder/templatename.blade.php ) <p>lorem ipsum dolor sit amet</p>  // resulting file <div class="bla">   <!-- folder/subfolder/templatename.blade.php -->   <p>lorem ipsum dolor sit amet</p> </div> 

imagine developer needs implement feature 2 years later. generated comments able view sourcecode in browser , know every temolate located in project.

that can achieved extending blade, though it's bit hacky. think laravel should provide cleaner interface extend blade.

well did, extending blade , creating @commentinclude directive. logic of include extracted laravels compileinclude() method. added comment , line break in front of it. since references contain characters of whole control structure (('viewname') need rid of them first. replaced dots / characters

blade::extend(function($view, $compiler) {     $pattern = $compiler->createopenmatcher('commentinclude');     $replace = '$1<?php echo "<!-- " . str_replace(["(\'", ".", "\'"], ["", "/", ""], "$2" ) . " -->\r\n" . $__env->make$2, array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render() ?>';     return preg_replace($pattern, $replace, $view); }); 

usage example:

@commentinclude('my.view.file') 

i wonder if provide cleaner solution that.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -