Created
March 17, 2012 16:40
-
-
Save juzna/2062020 to your computer and use it in GitHub Desktop.
{if authorized} macro for nette
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Now</h1> | |
1/ latte macros | |
{if $user->isLoggedIn()} | |
<a n:href="like! $item->id">Like</a> | |
{else} | |
Login to like it | |
{/if} | |
2/ n:macros | |
<a n:if="$user->isLoggedIn()" n:href="like! $item->id">Like</a> | |
<h1>Better?</h1> | |
1/ first way | |
{ifAuthorized like! $item->id} | |
<a n:href="like! $item->id">Like</a> | |
{else} | |
Login to like it | |
{/ifAuthorized} | |
2/ n:macros | |
<a n:ifAuthorized="like! $item->id" n:href="like! $item->id">Like</a> | |
<h1>Even better?</h1> | |
1/ first way | |
{ifAuthorized} {* don't wanna repeat the signal and parameters here *} | |
<a n:href="like! $item->id">Like</a> | |
{else} | |
Login to like it | |
{/ifAuthorized} {* here it would check if all links passed authorization, and discard the section if not so *} | |
2/ n:macros | |
<a n:href="like! $item->id" n:ifAuthorized>Like</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Handle action, only valid for a logged-in user | |
* @User | |
*/ | |
public function handleLike($itemId) { ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment