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

Check if template implements given interface #278

Open
janbarasek opened this issue Nov 6, 2021 · 2 comments
Open

Check if template implements given interface #278

janbarasek opened this issue Nov 6, 2021 · 2 comments

Comments

@janbarasek
Copy link

Hello,

Quite often I need to get a template from a user that can render my mandatory parameters and not use anything else. For example, an email template in an e-shop can only use predefined parameters, and anything extra will be rendered incorrectly (because the variable does not exist).

Latte could include a native way to see what all parameters the template implements (plus a list of keys in the array, if it's a $var['abcd'] notation for example). At the same time, there should be a check.

The implementation may use, for example, a native PHP interface where we scan for real typehints for methods, or at least an array of parameters from the user.

I know I can compile the Latte template to native PHP code, and then verify the connection with PhpStan, but this behavior is simply not possible to run on a production server where we receive a specific template from the user.

Thank you.

@MartinMystikJonas
Copy link

MartinMystikJonas commented Nov 7, 2021

I am not sure I understand your use case correctly but how about macro {parameters} - it defines what parameters can be used in template and everything else is undefined. So you can just prepend this macto to template code from user and try to render it.

@MartinMystikJonas
Copy link

Problem with generating list of all used parameters and keys in the array is that it can be accessed dynamically.

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

2 participants