Asked by: Nick DuBois
We have a series of blade view templates that are out going emails and would like to create a simple way for our in house administration to preview these emails without actually sending them.
I could keep tract of, and provide filler variables but am very curious if there is a way to request a list of variables used in a view?
For example, I have a basic view "greeting.blade.php" that says:
Dear {{$customerFirstName}} {{$customerLastName}},
I'd like to:
$usedVariablesArray = getVariablesFromView("greeting");
And have it return:
['customerFirstName', 'customerLastName']
Is there anything built into laravel that provides this kind of functionality?
[EDIT] I'd like to do this from outside the view file in question.
public function previewEmailTemplate($templateName) {
$usedVariables = $getArrayOfVariables($template);
// Would return ['customerFirstName', 'customerLastName']
foreach($usedVariables as $aUsedVariable) {
$dummyValues[$aUsedVariable] = $aUsedVariable;
}
return view($template, $dummyValues)->render();
}
So this function would render the template with the variable names in the place of the variables.
Does that make my question clearer?
No comments:
Post a Comment