Create a custom image tag - Not working

65 views
Skip to first unread message

Sebastien

unread,
May 26, 2017, 12:06:27 AM5/26/17
to Fat-Free Framework
Hi,

I spent too many hours trying to replicate that example: https://fatfreeframework.com/3.6/template#extend and I can't make it work.

My site structure:
-- app
   -- config
   -- db
   -- lib
   -- modules
   -- tags
      imageviewhelper.php
-- themes
-- tmp
-- uploads
-- vendor
  -- bcosca
    -- fatfree
index.php


My custom image tag class (imageviewhelper.php) is under app\tags, using the same namespace. I'm using the exact same code as provided in the sample.

Here is the code I'm using to register the tag, on index.php, before calling "run" function.

\Template::instance()->extend('testimage', 'app\tags\ImageViewHelper::render');

And on a view file (html), I'm using this code (I also tried with f3 prefix)

<f3:testimage src="{{ @BASE.'/'.@image.filepath }}" crop="true" width="100" height="100" />
<testimage src="{{ @BASE.'/'.@image.filepath }}" crop="true" width="100" height="100" />

I added a print in the beginning of the 'render' function and I never see the message... so it seems f3 never detects the tag. Is there a way to debug and see the tag list?

Notes:
- The image path is good, it works when using a standard <img> tag
- The namespace is good, f3 finds my class when I'm calling manually app\tags\ImageViewHelper::render("abcd") in the index.php file
- I also tried the different approach used in the fabulog demo site, and I have the same issue.

It might be something stupid....but what?

Thanks



xfra35

unread,
May 26, 2017, 6:39:53 AM5/26/17
to Fat-Free Framework
I don't know where your issue comes from, but you should be aware of this:
  • templates are compiled and stored in TEMP folder
  • they get recompiled automatically when the original template is modified
  • they don't get recompiled when a tag handler is modified (ImageViewHelper::render in your case)
So it often happens that you need to manually clear the TEMP folder in order for the changes made to the tag handler to be effective.

As for debugging (not easy in this case), you should remember that the tag handler is called at compilation time. So if you echo something in it, you should expect to read it directly in the compiled HTML code. It might be more appropriate to log the debugging string in a file.

Sebastien

unread,
May 26, 2017, 7:45:29 AM5/26/17
to Fat-Free Framework
Even after clearing the tmp folder, the image is now showing.

Sebastien

unread,
May 26, 2017, 11:56:59 PM5/26/17
to Fat-Free Framework
I found the issue. When rendering my view, I was creating a new template object. I replaced everything by \Template::instance()->render()

Then I had a few other issues, but I found the tagHandler and Image tab from F3-Sugar, and everything is now working fine!

Thank you much
Reply all
Reply to author
Forward
0 new messages