Skip to content

Instantly share code, notes, and snippets.

@juzna
Created March 17, 2012 16:40
Show Gist options
  • Save juzna/2062020 to your computer and use it in GitHub Desktop.
Save juzna/2062020 to your computer and use it in GitHub Desktop.
{if authorized} macro for nette
<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>
/**
* 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