maxnuf / MaxnufSmarty

Zend Framework 2 Module that provides a Smarty rendering strategy
4 stars 3 forks source link

Can't {include} files with relative path #8

Open ghost opened 11 years ago

ghost commented 11 years ago

When trying to include a file by relative path, ie:

{include file="./subdirectory/file.tpl"}

an error is thrown from vendor/smarty/smarty/distribution/libs/sysplugins/smarty_resource.php:216:

Template './subdirectory/file.tpl' cannot be relative to template of resource type 'maxnufFile'

I was able to fix this by changing the string 'maxnufFile' to simply 'file' on lines 30 and 31 in MaxnufSmarty\Smarty\MaxnufSmarty. Though I'm not sure if that breaks anything else. Or perhaps there is already a way to allow relative includes via a config setting?

Here is the full stack trace:

0 /Users/markisacat/Sites/dance-rialto/vendor/smarty/smarty/distribution/libs/sysplugins/smarty_internal_resource_file.php(29): Smarty_Resource->buildFilepath(Object(Smarty_Template_Source), Object(Smarty_Internal_Template))

1 /Users/markisacat/Sites/dance-rialto/vendor/smarty/smarty/distribution/libs/sysplugins/smarty_resource.php(529): Smarty_Internal_Resource_File->populate(Object(Smarty_Template_Source), Object(Smarty_Internal_Template))

2 /Users/markisacat/Sites/dance-rialto/vendor/smarty/smarty/distribution/libs/sysplugins/smarty_internal_template.php(636): Smarty_Resource::source(Object(Smarty_Internal_Template))

3 /Users/markisacat/Sites/dance-rialto/vendor/smarty/smarty/distribution/libs/sysplugins/smarty_internal_templatebase.php(117): Smarty_Internal_Template->__get('source')

4 /Users/markisacat/Sites/dance-rialto/vendor/smarty/smarty/distribution/libs/sysplugins/smarty_internal_template.php(286): Smarty_Internal_TemplateBase->fetch(NULL, NULL, NULL, NULL, false, false, true)

5 /Users/markisacat/Sites/dance-rialto/data/Smarty/smarty_compile/56e3ccab3dbbb094b6055802928349438028de7e.maxnufFile.list.tpl.php(25): Smarty_Internal_Template->getSubTemplate('./partials/_cat...', NULL, NULL, NULL, NULL, Array, 0)

6 /Users/markisacat/Sites/dance-rialto/vendor/smarty/smarty/distribution/libs/sysplugins/smarty_internal_templatebase.php(180): content_51a7f425176743_05499958(Object(Smarty_Internal_Template))

7 /Users/markisacat/Sites/dance-rialto/vendor/maxnuf/maxnuf-smarty/src/MaxnufSmarty/View/Renderer/Renderer.php(105): Smarty_Internal_TemplateBase->fetch('/Users/markisac...')

8 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/View/View.php(205): MaxnufSmarty\View\Renderer\Renderer->render(Object(Zend\View\Model\ViewModel))

9 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/View/View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel))

10 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/View/View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))

11 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel))

12 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))

13 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))

14 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)

15 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(347): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent))

16 /Users/markisacat/Sites/dance-rialto/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(322): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))

17 /Users/markisacat/Sites/dance-rialto/public/index.php(12): Zend\Mvc\Application->run()

18 {main}

maxnuf commented 11 years ago

I'm not sure why this is not possible. I'll look into it.

There are other (better) ways to include files. This module uses the zend framework's templatepathstack and templatemapresolver.

In your module.config.php you'll have something like this:

return array(
    'view_manager' => array(
        'template_path_stack' => array(
            'myBlogModule' => __DIR__ . '/../template',
        )
    ),
);

So you could use:

   {include file="[myBlogmodule]form/blogForm.tpl"}

or

   {include file="static/file.tpl"}

The latter will most likely point to your Application module, because there you will have:

    'view_manager' => array(
        'template_path_stack' => array(
            __DIR__ . '/../template',
        ),

Note however that I've set the default_resource_type to maxnufFile. So If you're including a file like this:

   {include file="file:static/file.tpl"}

The standard file resource will be used, and you can't use zend view helpers as modifiers.