Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Using Dynamic Partial Names #171

Open
salvoV81 opened this issue Jul 18, 2017 · 6 comments
Open

Using Dynamic Partial Names #171

salvoV81 opened this issue Jul 18, 2017 · 6 comments

Comments

@salvoV81
Copy link

Hi,

I'm trying to load partial dynamically

{{#each metaData.sections}}
{{#if this.type}}
{{> this.type}}
{{/if}}
{{/each}}

but I get a ERR_CONTENT_DECODING_FAILED error on chrome, does anybody have any idea of what the issue could be?

I've tried various solutions but nothing seems to be working

{{> (this.type)}}

{{> ({{this.type}})}}

{{> "this.type"}}

{{> (lookup . 'this.type'}}

Nothing seems to do the trick.

Any suggestions?

@marmz
Copy link

marmz commented Jul 18, 2017

Maybe:
{{> (lookup . 'type')}}

(In HandleBars.js it works fine ...)

@salvoV81
Copy link
Author

tried as well... doesn't seem to be working.
I've also tried creating a helper but with no luck..

<?php
/**
 * This file is part of Handlebars-php
 *
 * PHP version 5.3
 *
 * @category  Xamin
 * @package   Handlebars
 * @author    fzerorubigd <[email protected]>
 * @author    Behrooz Shabani <[email protected]>
 * @author    Dmitriy Simushev <[email protected]>
 * @author    Jeff Turcotte <[email protected]>
 * @copyright 2014 Authors
 * @license   MIT <http://opensource.org/licenses/MIT>
 * @version   GIT: $Id$
 * @link      http://xamin.ir
 */

namespace Handlebars\Helper;

use Handlebars\Context;
use Handlebars\Helper;
use Handlebars\Template;
use Handlebars\Handlebars;

/**
 * The DynPart Helper
 *
 * @category  Xamin
 * @package   Handlebars
 * @author    Salvovac <[email protected]>
 * @copyright 2014 Authors
 * @license   MIT <http://opensource.org/licenses/MIT>
 * @version   Release: @package_version@
 * @link      http://xamin.ir
 */
class DynPartHelper implements Helper
{
    /**
     * Execute the helper
     *
     * @param \Handlebars\Template $template The template instance
     * @param \Handlebars\Context  $context  The current context
     * @param array                $args     The arguments passed the the helper
     * @param string               $source   The source
     *
     * @return mixed
     */

    public function execute(Template $template, Context $context, $args, $source)
    {    
        
        $name=$context->get($args);

        try{
            
            $h=$template->getEngine();
            $partial=$h->loadPartial($name);
            $buffer=$partial->render($context);

        }catch(Exception $e){

            
        }
        return $buffer;
    }
}

@marmz
Copy link

marmz commented Jul 18, 2017 via email

@salvoV81
Copy link
Author

salvoV81 commented Jul 18, 2017 via email

@marmz
Copy link

marmz commented Jul 18, 2017 via email

@salvoV81
Copy link
Author

salvoV81 commented Jul 18, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants