n:src – the missing twin brother of n:href

As you have probably guessed by now, I love Nette. The more it hurts when I see the documentation lag behind the quality of the framework. Although I don’t understand why Latte built-in macros don’t include n:src when the oh-so-useful n:href is there my main concern however, is that nowhere in the documentation you’ll find detailed information on how to add it yourself. You’re condemned to endlessly search through forum again and crawl through various outdated subdomains of nette.org.

Here’s my solution to the n:src alias based on a post in the cookbook and the built-in n:href macro. You can also take a peek an another post of mine on how to tweak your forms using macros. As always, hopefully it’ll save you some time.

This goes into your BasePresenter:

  1. span class=”st0″>’@src’‘NMacroNode $node, $writer’,
  2.     ‘extract(NCFix::$vars[‘‘me’‘], EXTR_REFS);
  3.     return \’ ?> src="<?php \’ . $me->macroLink($node, $writer) . \’ ?>"<?php \’;
  4.    ‘));
  5.  
  6.   $template->registerFilter($latte);
  7. }
  8.  

Yes, the code does has a high wtf factor. Just look at the n:href macro, this isn’t my invention :-) I still don’t think I fully understand it but it does the trick and does so reusing the built-in macro as much as possible.

Tags:

Leave a Reply