Tiles in TAL? Death of metal:macro?

So, not sure if this is genius or not, but....

We have some tal template layouts for our content types. These aren't going away just because mosaic is here. They shall remain to bridge the gap.

In the good 'ol days, I used METAL macros to maintain reusable blocks of html.

<div metal:use-macro="context/sidebar_macros/macros/editors_pick">Ed Pick </div>

Now that I've moved the tal from the macro into it's own tile, moved the view code into the tiles very own view, and registred with ZCML, I don't want to maintain two templates, so I replace the macro call with:

<div tal:omit-tag="" tal:content="structure context/@@rfasite.basetheme.tiles.editors_pick.EditorsPick"></div>

And it works. Yea!
I want to remove ALL my macros now and replace them with tiles!

Question: Is this good practice or tiles gone wrong? Is there a better way to merge good 'ol tal (or chameleon) with tiles

I see:

  • If the tile template has any <head> data - it's not magically pushed to the page's <head>
  • I have to use the dreaded structure keyword making security a bit harder to manage.


  • Browser layers!
  • Independent views!
  • ZCML registration!
  • DRY!
  • And Much, much more!

of course the documented <link rel="tile" \> doesn't work, because TAL/ZPublisher doesn't understand that.

Which makes me want to write a PortalTransform to make it work!
Or maybe I did it wrong?

Please advise.

I guess you want to use https://pypi.org/project/plone.app.blocks/ . That will take the tiles' head and place them in the pages head.

I agree. Looks like plone.app.blocks is already installed - it's required by mosaic.

and the "correct" way for blocks to see and use a tile:

A tile is identified by a placeholder element with a data-tile attribute containing the tile URL.

I'd much rather use that.

I'd like to go this path without having to get into layouts just yet.

I also remember seeing - I think in the old 'vision of deco' docs - that '++tile++/path/to/tile' was suggested, but I didn't see that implemented anywhere.

Ultimately, I'd like to use a tile as a replacement to metal:use-macro, and save layouts for mosaic - allowing me to use the 'new' tiles in 'old' templates.

data-tile should work as long as either your request or the view has IBlocksTransformEnabled enabled on it.

1 Like

This worked. Thanks!

Here is my complete example - a tweet button:
(maybe it's time I created my own blog)

Tile template:

 <script src="https://platform.twitter.com/widgets.js" type="text/javascript"></script>
 <a href="" class="twitter-share-button">Tweet</a>

in my 'story' template:

<div data-tile="./@@rfasite.basetheme.tiles.tweet">tweet button</div>

and my story view:

from zope.interface import implements
from plone.app.blocks.interfaces import IBlocksTransformEnabled 
from plone.dexterity.browser.view import DefaultView 

class StoryView(DefaultView):
    """ The Default View for Stories """

and my 'disadvantages' just disappeared.

Thank you @jaroel I feel like I leveled up a bit.
especially because I just totally guessed at the location of IBlocksTransformEnabled and nailed it.