Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    SaphiLC
    @SaphiLC
    xD
    Torben Köhn
    @TorbenKoehn
    public function output($page, $data = null)
    {
    
    #    APP INSTANCE
        $app        = \Base::instance();
    
    #    SET THE OPTIONS FOR THE TEMPLATE ENGINE
        $cache = realpath(getcwd() . '/' . str_replace('folder=', '', $app->get('CACHE').'view/'));
        $options = [
            'pretty'        => false,
            'paths'            => [$ui],
            'cache_path'    => $cache,
        ];
        if($app->get('LIVE')) $options['ttl'] = 3600;
    
    #    RENDER THE PAGE
        $view    = new Pug\Renderer($options);
    
    #    CHECK IF THE PAGE EXISTS OR GIVE AN ERROR
        $ui            = $app->get('UI');
    
        if(!$view->getCompiler->resolvePath($page)) {
            $app->error(404);
            exit;
        }
    
    #    SET THE DATA TO SEND TO THE TEMPLATE
        if(!$data)
        {
            $data = $app->hive();
        }
        $output    = $view->render($page, $data);
    
    #    RETURN THE PAGE AS A STRING
        return $output;
    }
    Bam
    If you have a file /my/views/some-page.pug
    and you have 'path' => ['/my/views']
    You can simply do $renderer->render('some-page')
    It will find the file automatically
    And if you need to check for the file, use $renderer->getCompiler()->resolvePath('some-page')
    SaphiLC
    @SaphiLC
    so i cant have files with the same name i guess?
    cause i do have those
    xD
    Torben Köhn
    @TorbenKoehn
    $renderer->render('some-sub-directory/some-page')
    That's where the cache structure actually kicks in
    And you generally can't have two files with the same name in one folder :P
    SaphiLC
    @SaphiLC
    ah yah
    not the same folder :P
    Torben Köhn
    @TorbenKoehn
    Does it work with this?
    SaphiLC
    @SaphiLC
    sec
    Torben Köhn
    @TorbenKoehn
    Make sure to remove all traces of the buggy cache folders
    And remove the realpath()
    If it doesn't exist, it will return null
    But it can not exist, since Tale Pug will just create it if it doesn't
    I made some typos in there :(
    SaphiLC
    @SaphiLC
    D:
    Torben Köhn
    @TorbenKoehn
    It's ->getCompiler()
    Not ->getCompiler
    Wait xD
    SaphiLC
    @SaphiLC
    @_@
    Torben Köhn
    @TorbenKoehn
    public function output($page, $data = null)
    {
    
        $app = \Base::instance();
    
        $options = [
            'pretty' => false,
            'paths' => [$ui],
            'cache_path' => getcwd() . '/' . str_replace('folder=', '', $app->get('CACHE').'view/'),
        ];
    
        if($app->get('LIVE')) $options['ttl'] = 3600;
    
        $view = new Pug\Renderer($options);
    
        $ui = $app->get('UI');
    
        if(!$view->getCompiler()->resolvePath($page)) {
    
            $app->error(404);
            exit;
        }
    
        if(!$data)
        {
            $data = $app->hive();
        }
    
        $output = $view->render($page, $data);
    
        return $output;
    }
    SaphiLC
    @SaphiLC
    u didnt use the $ui one :P
    nuuu my pretty comments QQ
    Torben Köhn
    @TorbenKoehn
    Oh yeahhhh...
    Yeah, my IDE did that, sorry
    SaphiLC
    @SaphiLC
    xD
    Torben Köhn
    @TorbenKoehn
    public function output($page, $data = null)
    {
    
        $app = \Base::instance();
    
        $ui = $app->get('UI');
    
        $options = [
            'pretty' => false,
            'paths' => [$ui],
            'cache_path' => getcwd() . '/' . str_replace('folder=', '', $app->get('CACHE').'view/'),
        ];
    
        if($app->get('LIVE')) $options['ttl'] = 3600;
    
        $view = new Pug\Renderer($options);
    
        if(!$view->getCompiler()->resolvePath($page)) {
    
            $app->error(404);
            exit;
        }
    
        if(!$data)
        {
            $data = $app->hive();
        }
    
        $output = $view->render($page, $data);
    
        return $output;
    }
    Like this
    SaphiLC
    @SaphiLC
    what evil IDE do u use? :C
    Torben Köhn
    @TorbenKoehn
    PHPStorm
    There basically is just one single real IDE for PHP :)
    So, does it work?
    SaphiLC
    @SaphiLC
    :D
    yah
    Torben Köhn
    @TorbenKoehn
    It's magic
    SaphiLC
    @SaphiLC
    nah
    unless u are magic
    :P
    Torben Köhn
    @TorbenKoehn
    Pretty sure it's magic
    SaphiLC
    @SaphiLC
    xD
    thanks :)
    Torben Köhn
    @TorbenKoehn
    No problem :)