Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How many placeholder were substituted #22

Open
obstschale opened this issue Sep 21, 2023 · 1 comment
Open

How many placeholder were substituted #22

obstschale opened this issue Sep 21, 2023 · 1 comment

Comments

@obstschale
Copy link

obstschale commented Sep 21, 2023

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant