We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Could not use my own view helper in Volt

Hi, I write my own view helper as below:

<?php
namespace Tartan;

class Tag extends \Phalcon\Tag
{
    static public function gtoj($date)
    {
        [...]
        return $response;
    }
}

then I added my own tag service in DI in my application bootstrap:

$di->set('tag', function() {
    return new \Tartan\Tag();
});

NOW, I can use my helper like below and it works perfectly

<?php echo $this->tag->gtoj('2014-03-03'); ?>

but I can`t use it in Volt like

{{ gtoj("2014-03-03") }}

and I got following error:

Phalcon\Mvc\View\Exception: Undefined function 'gtoj' in /home/aboozar/www/2013/blue/app/modules/Panel/views/merchant/index.phtml on line 17

other tag helpers like {{ link_to("products/search", "Search") }} works in the same file too.

any Idea?



2.9k

hi,

take a look at this page, you'll find your answer : http://docs.phalcon.io/en/latest/reference/volt.html#id3



18.4k
Accepted
answer

You can use it in volt like

 {{ tag.gtoj("2014-03-03") }}
edited Mar '14

Dear @Ivan Vorontsov your answer is correct. Thank you. but how I can accept your answer? "Accept answer" button doesn`t show in your reply!!!


(I can see only Reply/Disike/Like buttons) I thinks this is a forum bug.