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

jSmart conditional & loop statement are not working with React-JS. #23

Closed
madoffcharles opened this issue Dec 3, 2017 · 4 comments
Closed
Assignees
Labels

Comments

@madoffcharles
Copy link

In my React-JS Project, I am trying to use the smarty template. It is working for variables but it is not working at all for the loop and conditional statement.
I have following code written in my template :
Following Data From Template
<div>
Simple Data Passing <br/>
<h1>{$data}</h1>
<hr/>
for loop code : <br/>
{$ar = ['a','b','c','d']}
{for $i=0 to $ar|count-1 max=3}
{$ar[$i]}
{/for}
<hr />
if statement : <br/>
{assign var='xyz' value="1"}
{if '1' eq $xyz }
if condition working
{else}
if condition is not working
{/if}
</div>

Which is giving following output :
<div>Simple Data Passing <br>
<h1>Hello World</h1>
<hr>
for loop code : <br>

<hr>
if statement : <br>
{if '1' eq $xyz }
if condition working
{else}
if condition is not working
{/if}
</div>

Here I am passing the $data as "Hello World" it is working properly, but the below of for each is not working.
So could you please help me with this?

@umakantp
Copy link
Owner

umakantp commented Dec 14, 2017

You have to register count modifier yourself in the new jSmart version. It has been removed in new version like Smarty did. Here is smarty link documentation which shows no mention of |count modifier:- https://www.smarty.net/docs/en/language.modifiers.tpl

Below is an example of the count modifier:-

jsmart.prototype.registerPlugin(
    'modifier',
    'count',
    function (a) {
      return a.length;
    }
  );

@umakantp
Copy link
Owner

Hi @madoffcharles

I investigated and found that even though the count modifier documentation doesn't exist it still works in case of PHP Smarty.

In that case, I'm adding the count modifier again.

@umakantp umakantp added the bug label Jan 11, 2018
@umakantp umakantp reopened this Jan 11, 2018
@umakantp
Copy link
Owner

Your if comes as it is because there is space at the end of curly brace in if statement
{if '1' eq $xyz }

It should be

{if '1' eq $xyz}

Read more about it on https://github.com/umakantp/jsmart/wiki/auto_literal

@umakantp
Copy link
Owner

Now that I have pushed changes and new version will be released with the fix i.e. having count method, I'closing the bug.

@umakantp umakantp self-assigned this Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants