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

Nested template vars not being evaluated #4

Open
goharahmed opened this issue Feb 1, 2024 · 3 comments
Open

Nested template vars not being evaluated #4

goharahmed opened this issue Feb 1, 2024 · 3 comments

Comments

@goharahmed
Copy link

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

fefit commented Feb 17, 2024

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

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

fefit commented Apr 16, 2024

@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.

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