fefit / fet

A golang template engine that can compile code into `html/template`, use syntax like the php template engine smarty.
MIT License
27 stars 4 forks source link

Nested template vars not being evaluated #4

Open goharahmed opened 7 months ago

goharahmed commented 7 months ago

Hi, Great library, thank you. Its working fine for the most part but when we've a template variable like this

$account.1.server.1.address

then it throws an error

Error: wrong identifier token

I've tried to debug and it basically doesn't like the token "server" possibly since the previous token did not have a $ to it? Can you elaborate how we can have a dynamic data map plugged into the template variable for example the above one: $account.1.server.1.address could possibly have var data map[string][]map[string][]map[string]interface{}

fefit commented 7 months ago

@goharahmed sorry for the late reply, there is indeed issue here, the parsing process does not adapt well to float numbers (1.) and field reading. A simple solution would be to modify it to the following:

$account["1"].server["1"].address

The meanwhile, square brackets can effectively handle the distinction between keys that are numeric or string types too.

goharahmed commented 7 months ago

Thank you so much for clarification. Because we have sheer amount of template files that we can not spend too many months fixing the template files. Smart way would be to invest into this library to make it work. Even better option was to use original PHP smarty, which we followed, and we got our desired results.

Still, the code base now has a PHP component which we would love to eliminate and switch to this library whenever possible.

If you can only direct me to the file in this repo, plus some pointers as what you think will be needed to make it work, then I will spend some time to figure this patch out and possibly send a PR to you.

Thanks for responding.

fefit commented 5 months ago

@goharahmed We should have had a similar situation in the past. This project was originally developed to facilitate others to switch from PHP Smarty to golang template without spending too much learning cost. However, there is still a lot of work to be done to fully realize the features of smarty, and part of the lexical analysis code in the project was rough. For a while, I was planning to refactor this part of the code (in the feature optimizeExp), but it basically stalled due to many other things. Now I don't have much time to maintain the project. If you have particularly large needs, you can fork a new project based on it, and add the features what you want. Sorry for the late reply, I've been too busy recently and don't manage my time very well.