Skrol29 / tinybutstrong

TBS is a PHP template engine for pro and beginners. Only 1 class with few methods properties, but it can do may things for any text templates, including HTML and XML. The only engine that enables W3C compliant templates. It has many plugins including OpenTBS.
http://www.tinybutstrong.com
60 stars 18 forks source link

using magnet to remove attribute resulting in bad render #19

Closed doppynl closed 3 years ago

doppynl commented 3 years ago

I'm upgrading an app that uses an older version of tinybutstrong, to a more recent version to get it to run on php7 (and 8) as well as start using composer.

I run into a possible bug when an attribute is to be removed from the template using magnet config. It could also be I'm doing something wrong.

I can reproduce the problem with a small bit of code+template. The following started failing in 3.10.0. Using version 3.9.0 works just fine.

<?php
require __DIR__ . '/../tbs_3100/tbs_class.php';

$tbs = new clsTinyButStrong();
$tbs->loadTemplate(__DIR__ . '/template.html');

$items = [
    ['url' => '/wherever', 'target' => '_blank', 'follow' => 'nofollow', 'name' => 'just a label' ],
    ['url' => '/wherever', 'target' => '',       'follow' => '',         'name' => 'just a label' ],
    ['url' => '/wherever', 'target' => '',       'follow' => '',         'name' => 'just a label' ],
    ['url' => '/wherever', 'target' => '_blank', 'follow' => 'nofollow', 'name' => 'just a label' ],
];

$tbs->MergeBlock('items', $items);

echo PHP_EOL . $tbs->Source . PHP_EOL;

template.html :

<ul>
  [items;block=begin;bmagnet=ul]
  <li>
    <a href="[items.url;magnet=li]" target="[items.target;magnet=#]" rel="[items.follow;magnet=#]">
      [items.name;ope=upper1]
    </a>
  </li>
  [items;block=end]
</ul>

This results in the following output:

<ul>
  <li>
    <a href="/wherever" target="_blank" rel="nofollow">
      Just a label
    </a>
  </li>
  <li>
    <a href="/wherever">
      Just a label
    </a>
  </li>
  <li>
    <a href="/wherever"items.target;magnet=#]"items.follow;magnet=#]">
      Just a label
    </a>
  </li>
  <li>
    <a href="/wherever" target="_blank" rel="nofollow">
      Just a label
    </a>
  </li>
</ul>

As you can see the first 2 items go fine, but whenever it needs to remove the same attribute for the next row again it fails for some reason. Am I doing something wrong here? or was a bug introduced in version 3.10 ?

Thanks.

Skrol29 commented 3 years ago

That is a bug, I’m working it.

Skrol29 commented 3 years ago

The bug is fixed with TBS version 3.12.2

doppynl commented 3 years ago

Thanks, that appears to have solved my issue.

The new version is not on packagist yet however, and I would like to install it with composer. Can you trigger an update in packagist?

Or better, you can configure auto-updates on packagist, how is explained here: https://packagist.org/about#how-to-update-packages

Skrol29 commented 3 years ago

I’ve triggered the update and also I’ve set up the webhook for the auto-update.

Thanks :-)