Fluid Tipp 13: Inhalt von "Sections" Variablen zuweisen


Es ergibt durchaus Sinn, Sektionen zu verwenden, um doppelten Code zu vermeiden. Es kann zusätzlich noch hilfreich sein, den Inhalt einer Variable zuzuweisen. Diese ist danach auch beliebig oft wiederverwendbar und kann vordefinierte Argumente übergeben. Im folgenden Beispiel ist das gut zu erkennen.

<!-- Using f:render to make "blocks" of output -->
Rendering into a variable and then using that variable
can make the template more readable. This example is
VERY small; the bigger and more costly the rendering is,
the more sense it makes to use this trick.

<f:section name="Icon">
  <span class="icon-{icon}"></span>
</f:section>

{f:render(section: 'Icon', arguments: {icon: 'twitter'}) -> f:variable(name: 'twitterIcon')}
{f:render(section: 'Icon', arguments: {icon: 'facebook'}) -> f:variable(name: 'facebookIcon')}

And use them as frequently as we want:

<div class="share">
  Share here!
  {twitterIcon -> f:format.raw()}
  {facebookIcon -> f:format.raw()}
</div>

<div class="also-share">
  Or here!
  {twitterIcon -> f:format.raw()}
  {facebookIcon -> f:format.raw()}
</div>

Kategorien

  Devblog

Hat dir der Artikel gefallen?

Werkraum News:

Titelbild zur Teamevent-News: Im Hintergrund sieht man Entwickler am Notebook, darüber ist ein Code multipliziert und das Bild ist orange eingefärbt.

Neues Jahr, neuer Code

Mit Spaß an der Arbeit und Geselligkeit, so funktionierte das Teamevent #27 bei werkraum