Variable visibility in blocks
Notice: This thread is very old.
- pistols
- Member | 26
Hello there, i have a quite strange behaviour in my latte.
This latte file should show an extra <script> block if there are errors in the form processing. As you can see i define the $errors as a “global” to the latte file.
Later I want to change its value if an error comes up and show the div accordingly. The problem is that the $errors variable in the scripts block always validates as in the definition {var $errors = 0}.
Any ideas what am i doing wrong?
<?php
{layout "../@login.latte"}
{var $errors = 0}
{block content}
<section class="container">
<section class="login-form">
{form signInForm}
<div n:if="$form->ownErrors" n:foreach="$form->ownErrors as $error" class="alert alert-danger" style="margin-top: 0px"><span class="glyphicon glyphicon-remove"></span> {$error}</div>
{php
if ($form->ownErrors) {
$errors = 1;
} else {
$errors = 0;
};
}
<img src="{$basePath}/images/logo.png" class="img-responsive center-block" alt="" />
<input n:name="username" placeholder="Přihlašovací jmeno" required class="form-control input-lg" />
<input n:name="password" type="password" placeholder="Heslo" required class="form-control input-lg" />
<button type="submit" name="send" class="btn btn-lg btn-block btn-primary">Přihlásit</button>
{/form}
</section>
</section>
{/block}
{block scripts}
{include #parent}
<script n:if="$errors == 1">
$(function() {
$(".login-form").effect("shake");
});
</script>
{/block}
?>