Jump to content

Why I love the Latte Template Engine


bernhard
 Share

Recommended Posts

6 minutes ago, dotnetic said:

think you can drop the parentheses after items or content. Also you might want to use a n:if clause on the ul, so the markup is discarded if there are no items.

No, because $block is a rockmatrix block having an items() method but not having an items property. Same goes for content(). The whole block will only render if there are items using RockFrontend's renderIf() method:

$rockfrontend->renderIf("sections/newsitems.latte", $block->items())

 

10 minutes ago, dotnetic said:

Or just use

{dump $page->title}

Thx for letting me know 🙂 Though personally I don't see any benefit in using another syntax if I can simply use plain PHP (which I already know)...

  • Like 1
Link to comment
Share on other sites

19 minutes ago, dotnetic said:

I am also using Latte in an actual project and love it so far. For the integration into ProcessWire I am using  TemplateEngineFactory. It also has a Latte renderer (but with Latte 2 atm, actual version is 3).

Did you run into any breaking changes upgrading from Latte 2 to 3? I haven't yet updated the Latte renderer for TemplateEngineFactory as I haven't had enough time to give Latte 3 a go.

Link to comment
Share on other sites

3 minutes ago, d'Hinnisdaël said:

Did you run into any breaking changes upgrading from Latte 2 to 3

I did not upgrade yet, I am in the process of integration Latte v3 into the TemplateEngineLatte renderer, but still need time for it. Right now I am using v2

Link to comment
Share on other sites

13 minutes ago, bernhard said:

Thx for letting me know 🙂 Though personally I don't see any benefit in using another syntax if I can simply use plain PHP (which I already know)

This is just syntactic sugar and uses Tracys debug bar, similar to using `{bd ($myvar)}.

Using things like tags and filters are also syntactic sugar. 

{$page->intro|noescape}
// or
<div n:if="$features">

Tags have some advantages over plain PHP in the template context. For example they are chainable and easy to read/write:

{$page->intro|noescape|upper} // outputs unescaped HTML content in uppercase

 

Link to comment
Share on other sites

6 minutes ago, dotnetic said:

This is just syntactic sugar and uses Tracys debug bar, similar to using `{bd ($myvar)}.

It still looks like it's doing the exact same thing to me?

  {dump $site}
  {bd($site)}

image.thumb.png.450aea2c3ff4009df5c82f418edc692a.png

I'd hoped that your version might make the click below the dump work so that I end up at the correct line in my latte file, but it always leads me to the cached/compiled version of latte...

Link to comment
Share on other sites

1 hour ago, bernhard said:

It still looks like it's doing the exact same thing to me?

 

Yes exactly but with an easier syntax (imho), but dump is just one example.

I don't know anything about the caching, and yeah it is bad that not the real file is shown in the dump

Link to comment
Share on other sites

  • 1 month later...

PM: "can we have the separator line not only on top of each list item but also after the last one?"

<div n:foreach="$block->steps() as $step">
  {$rockfrontend->render('img/hr.svg')}
  <div>...</div>
  {$rockfrontend->renderIf('img/hr.svg', $iterator->last)}
</div>

The $iterator is available automatically in LATTE loops! And it plays perfectly together with renderIf() 😎

See https://latte.nette.org/en/tags#toc-iterator

Link to comment
Share on other sites

PHP is for me unfortunately something that does not come very inuitive (so, I guess you know now I am by no means a hardcore developer).
So it´s always time consuming with lots of trial and error to find (forum, google) code snippets that do what I want to do.

Since I started using LATTE thanks to this thread and thanks to @bernhard and his RockFrontend module, it seems like a gamechanger for me.
Processwire has become extremly more usefull and inutitive for me since. Thank you!

I am currently rebuilding my code templates I use as starter-kits for new projects and convert them to LATTE. 

Does anyone have and is willing to share a skeleton template to build a nav-tree menu (mulitlevel) with LATTE?

Something that produces similar HTML code like this:

<ul class='navbar-nav'>
  <li class='nav-item  active'>
    <a href='/processwire/' class='nav-link'>Home</a>
  </li>
  <li class='nav-item dropdown'>
    <a href='/processwire/kontakt/' class='nav-link dropdown-toggle'>Kontakt</a>
    <ul class='dropdown-menu'>
      <li class='nav-item'>
        <a href='/processwire/kontakt/kontakt-unterseite-a/' class='dropdown-item'>Kontakt Unterseite A</a>
      </li>
    </ul>
  </li>
  <li class='nav-item'>
    <a href='/processwire/seite-b/' class='nav-link'>Seite B</a>
  </li>
</ul>

  • Like 1
Link to comment
Share on other sites

8 minutes ago, maetmar said:

Does anyone have and is willing to share a skeleton template to build a nav-tree menu (mulitlevel) with LATTE?

Just wanted to point out that when it comes to building menus, it can get a bit... complicated. This is why modules such as MarkupMenu exist. I'm not saying that you can't build your own menu logic without a module using custom code, just that it's — in my opinion — one of those things that you don't necessarily need to 🙂

Depends a lot on your use case, of course; some sites have a super simple menu logic. And sorry for going off-topic, as well as shameless self-promotion via MarkupMenu 🙂

Link to comment
Share on other sites

On 9/23/2022 at 2:25 PM, maetmar said:

Since I started using LATTE thanks to this thread and thanks to @bernhard and his RockFrontend module, it seems like a gamechanger for me.
Processwire has become extremly more usefull and inutitive for me since. Thank you!

Thx! I'm happy to hear that 🙂 

This is a completely recursive multi-level menu using LATTE + RockFrontend magic that should get you started 🙂 

<ul class="uk-nav uk-nav-primary uk-margin-top uk-margin-large-bottom">
  {* define block that is used for recursion *}
  {define items, $items, $first}
    {foreach $items as $item}{* loop all items*}
      {* define variables for inside the loop *}
      {var $active = $rockfrontend->isActive($item)}
      {var $subid = "tm-menu-".$item->id}
      {var $numc = ($item->numChildren() && $item!==$first) }
      {* list item markup *}
      <li n:class="$active ? 'uk-active'">
        <a href="{$item->url}" n:attr="rf-toggle: $numc ? '#'.$subid">
          {$item->title}
          <svg n:if="$numc" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--tabler" width="20" height="20" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m6 9l6 6l6-6"></path></svg>
        </a>
        {* list for child-items *}
        <ul id="{$subid}" n:if="$numc" class="uk-nav-sub" {!$active?'hidden'}>
          {include items, $item->children()->prepend($item), $item}
        </ul>
      </li>
    {/foreach}
  {/define}
  {* now include the block for the first level of items *}
  {include items, $home->children()}
</ul>

 

  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...