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

Question: Getting values from an html template #504

Closed
jaidenbm0127 opened this issue Jul 28, 2022 · 1 comment
Closed

Question: Getting values from an html template #504

jaidenbm0127 opened this issue Jul 28, 2022 · 1 comment

Comments

@jaidenbm0127
Copy link

jaidenbm0127 commented Jul 28, 2022

I know similar questions have been asked before, but I was just wondering if anything more solid has been implemented yet for getting these values from a given template.

For example, say I grab template X.html from a folder that contains the values {{FirstName}} and {{LastName}}. Is there a way of grabbing the variable names of each of those items regardless of the template chosen? That way I can compare that incoming data in form of say a Dictionary<string, string> and ensure it has a matching key-value pair for each of the values in the template.

I was wondering if I could do something like this for validation purposes ie make sure that a document has certain/all values filled.

Following this post I could do FluidTemplate.Statements but wasn't sure where to go from there (like how to filter the tags for example)

@sebastienros
Copy link
Owner

I would require a visitor patter in Fluid to be able to go over anything that is parsed and extract all identifiers. You could build a simpler parser though that would only read {{ value }} statements. But it can be more complex with loops, conditions, ... which also use properties from the model.

Parlot which is the underlying parser exposes an event when a sub-element is analyzed. But I am not sure it exposes an event when a node is actually found, probably because it could discard it later on when there is an ambiguity that will then be resolved.

In the meantime, I would suggest to go over each statement, then check for the types you want to handle, recursively, and finally detect indentifiers (look for IdentifierSegment in MemberExpression objects).

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