Template “array/multi/stack/…” block
- bene
- Member | 82
I would like to define special block in layout. E.g.
{renderArrayBlock #js}{/renderArrayBlock}
.
In content or partial template I would like to write
{pushToArrayBlock #js}<script>...</script>{/pushToArrayBlock}
so many times as I need.
{renderArrayBlock #js}
render all
{pushToArrayBlock #js}
which I was defined.
Maybe this funkcionality is implemented in regular block, but I can't find it in documentation.
Thanks
- chemix
- Nette Core | 1310
@layout.latte
<!DOCTYPE html>
...
{#scripts}
<script src="{$basePath}/js/jquery.js"></script>
<script src="{$basePath}/js/main.js"></script>
{/#}
</html>
Homepage/default.latte
...
{#scripts}
{include #parent}
<script src="{$basePath}/js/homepage.js"></script>
{/#}
but best way is only one js.min file to have https://developers.google.com/…ices/request
for minification javascript i use Grunt and heve this code
{if $develMode}
<!-- build:js {$basePath}/js/app.min.js -->
<script src="{$basePath}/js/netteForms.js"></script>
<script src="{$basePath}/js/helpers.js"></script>
<script src="{$basePath}/js/lightbox.js"></script>
<script src="{$basePath}/js/layout.js"></script>
<script src="{$basePath}/js/homepage.js"></script>
<!-- endbuild -->
{else}
<script src="{$basePath}/js/app.min.js?{$version}"></script>
{/if}
other nette way is use addon webloader http://translate.google.com/translate?…
- bene
- Member | 82
This is not what I need.
Example:
File: @layout.latte
@layout<br />
{include #content}
{renderArrayBlock #js /}
File: index.latte
{#content}
index<br />
{pushToArrayBlock #js}
#js: index<br />
{/pushToArrayBlock}
{include '_partial1.latte'}
{include '_partial2.latte'}
{/#}
File: _partial1.latte
_partial1<br />
{pushToArrayBlock #js}
#js: _partial1<br />
{/pushToArrayBlock}
File: _partial2.latte
_partial2<br />
{pushToArrayBlock #js}
#js: _partial2<br />
{/pushToArrayBlock}
I want to output:
@layout
index
_partial1
_partial2
#js: index
#js: _partial1
#js: _partial2
- petr.pavel
- Member | 535
I'm afraid this isn't possible with the built-in block handling. If you look into \temp\cache\_Nette.FileTemplate, you'll notice that Latte blocks are in fact, converted to functions. These functions are then called when a block needs to be rendered.
Since you can't add to a function definition, blocks can't be used per se.
I suggest you take a look at this post (translate with Google Translate,
sorry):
https://forum.nette.org/…radcich-kodu
and this add-on (one of the alternative options mentioned in the post
above – links “poměrně”, “často” and “řeší”):
https://componette.org/search/?…