Pass multiple parameters to a blade directive

前端 未结 9 1755
时光说笑
时光说笑 2021-02-19 07:31

I\'m trying to create a blade directive to highlight some words that will return from my search query.

This is my blade directive:

class AppServiceProvid         


        
9条回答
  •  半阙折子戏
    2021-02-19 07:52

    I found an alternative approach to accessing View variables within a Blade Directive.

    I wanted to check whether a given string appeared as an array key in a variable accessible in the view scope.

    As the Blade Directive returns PHP which is evaluated later, it is possible to 'trick' the Directive by breaking up a variable name so that it doesn't try to parse it.

    For example:

        Blade::directive('getElementProps', function ($elementID) {
            return "";
        }); 
    

    In this example we have split the $elementData variable name so the Blade Directive treats it like a spring. When the concatenated string is returned to the blade it will be evaluated as the variable.

提交回复
热议问题