handlebars-php icon indicating copy to clipboard operation
handlebars-php copied to clipboard

How many placeholder were substituted

Open obstschale opened this issue 2 years ago • 1 comments

Is there a way to find out which variable/placeholder was substituted or a default value has been used?

We need to calculate, which placeholder was actually used. In our example, we will render one template multiple times with different values provided. And we would like to show to the user, which placeholder were problematic, because of missing data.

Either handlebar-php keeps track of the substitutions and I can get statistics from it. Or I could get a list of all placeholder within the template, so I can check myself, which data is present before rendering.

obstschale avatar Sep 21 '23 15:09 obstschale

I found a solution: I have create a new Context class, which overrides the get-method. This allows me, to keep track of all used variables and it's values. That Wrapper-Context can return all placeholder and count statistics about their usage.

The only thing I need to figure out is, how to count how many default-values were used. I probably will also use Wrapper-Helper class and override the default Helper class.

obstschale avatar Sep 22 '23 14:09 obstschale