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

New Feature #14

Closed
huynhminhson opened this issue Jan 4, 2014 · 2 comments
Closed

New Feature #14

huynhminhson opened this issue Jan 4, 2014 · 2 comments
Labels

Comments

@huynhminhson
Copy link

I need to integrate many PHP codes into html, can Snow just parse codes between tag or ? This will make Snow much more flexible and very helpful to me.

@AndCake
Copy link
Owner

AndCake commented Jan 4, 2014

Well, I don't like this meshing of display, data and logic that PHP favors so much, since it will make code a lot more difficult to read, maintain and in general doesn't follow coding best-practices. So I won't add <?snow ... ?> for HTML files (that's what templates are meant for).

I would recommend to use the MVC pattern on those codes you'd like to add to HTML. Because then you can just continue using Mustache without sacrificing proper division of labor and responsibilities in the code. For example, if you have functionality like this in PHP:

<ul>
    <? if ($_SERVER["REMOTE_IP"] > 127 && count($mydata->queryCustomer($_SESSION["id"])) > 0) { ?>
        <li>Real user logged in</li>
    <? } ?>
</ul>

You could turn that into a proper data function (coming from a class or just from an array):

echo template "loginstatus", ["loggedIn": fn <- _SERVER["REMOTE_IP"] > 127 and mydata.queryCustomer(_SESSION["id"])??]

And the template would look like that:

<ul>
    {{#loggedIn}}
        <li>Real user logged in</li>
    {{/loggedIn}}
</ul>

Does that make sense to you?

@huynhminhson
Copy link
Author

OK, I see. Thanks a lot for your help 👍

@AndCake AndCake closed this as completed Jan 5, 2014
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