i am trying to install 'EdpModuleLayouts'
i have followed the instruction for the module here:
i also followed the issue here:
i. e; I placed the following code in my application.config.php?
return array(
'modules' => array(
... ,
'EdpModuleLayouts'
)
);
i then placed the following code in my module config
'view_manager' => array(
'template_path_stack' => array(
'workers' => __DIR__ . '/../view',
'Workers/layout' => __DIR__ . '/../view/layout/layout.phtml'
),
),
'module_layouts' => array(
'Workers' => 'Workers/layout'
),
i got the following error report:
Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException'
with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render
template "Workers/layout"; resolver could not resolve to a file' in
zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php
on line 499
The error message is so specific.
Unable to render template "Workers/layout"
This means that there is no template Workers/layout defined within the view_manager configuration. And the trick here is that you made a simple mistake of placing the configuration at the wrong place.
template_path_stack is used to give the view_manager information about some folders where template files are mapped going by their file-path.
template_map is used to give the view_manager information about which file covers a specific template.
The difference of the two can easily be seen when checking the module.config.php of the ZendSkeletonApplication. With this in mind, all you have to do is to change your configuration.
Another hint: don't CamelCase configuration keys, keep them lowercased ;)
'view_manager' => array(
'template_path_stack' => array(
'workers' => __DIR__ . '/../view',
),
'template_map' => array(
// consider to make this lowercase "workers/layout"
'Workers/layout' => __DIR__ . '/../view/layout/layout.phtml'
)
),
'module_layouts' => array(
'Workers' => 'Workers/layout'
),
Related
I am trying to allow users to select from existing images in the system and have context set like the provided example and this works. How can I stop the users from selecting from any other context type?
$form->add('image', 'sonata_type_model_list', array(), array('link_parameters' => array('context' => 'news')))
Not tested but I just stumbled over the parameter: hide_context
$form->add('image', 'sonata_type_model_list', array(), array(
'link_parameters' => array(
'context' => 'news',
'hide_context' => true
)
))
Maybe you want to give it a try?
I use a silex with twig;
I create custom form_div_layout and put it in the webroot( for example)
I register TwigService provider like this
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/../views',
'twig.options' => array(
'cache' => __DIR__ . '/../cache/twig',
'strict_variables' => false
),
'twig.form.templates'=> [WEBROOT . '/form_div_layout.twig']
));
but i have an error
Twig_Error_Loader: Template "/home/versh/sale/web/form_div_layout.twig" is not defined () in "layout.twig" at line 52.
how to register theme correctly ?
I know that if i put theme in the twig.path it will work, but this is not solution
I'm using Twig with namespaces and I think it is the most flexible practice:
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.options' => array(
'cache' => true,
'strict_variables' => true,
'debug' => false,
'autoescape' => true
)
));
// set namespace for your application
$app['twig.loader.filesystem']->addPath(WHERE_EVER_YOU_WANT_PATH, 'yourApplication');
Now you can render templates using the namespace:
return $app['twig']->render('#yourApplication/sample.twig', array());
you can define as many namespaces as you need.
You have to add base template form_div_layout.html.twig to twig.form.templates option too.
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../views',
'twig.options'=>array(
'cache' => __DIR__.'/../cache',
),
'twig.form.templates' => array(
'form_div_layout.html.twig',
'theme/form_div_layout.twig'
),
));
In ./config/application.config.php
return array(
'modules' => array(
'Application',
'Admin',
)
...
I have 2 separate set of layouts, ./module/Application/view/layout/layout.phtml and ./module/Admin/view/layout/layout.phtml
In ./module/Admin/config/module.config.php
...
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'header' => __DIR__ . '/../view/layout/header.phtml',
'footer' => __DIR__ . '/../view/layout/footer.phtml',
'paginator' => __DIR__ . '/../view/layout/paginator.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
)
...
In ./module/Application/config/module.config.php
...
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'header' => __DIR__ . '/../view/layout/header.phtml',
'footer' => __DIR__ . '/../view/layout/footer.phtml',
'paginator' => __DIR__ . '/../view/layout/paginator.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
)
...
Basically they are different set and some of the content are different. Unfortunately, both module only load the layout located in In ./module/Admin/config/module.config.php
I googled but didn't fount any solution that I want. Anyone has any idea on this?
You may be interested to know, what your configuration actually does. My Blog Post about this Topic, may interest you. Ultimately all Configuration files will be merged to one. The global configuration keys are not on a per-module basis ;)
To achieve your goal you should read Evan Courys Blog Post "Module-specific layouts in ZF2"
Evan provides a Module "EdpModuleLayouts" that makes things pretty easy. If however you only need one alternative Layout for your AdminModule, then i suggest you simply go with the example code of his Blog Post to set an alternate Layout for your AdminModule directy via your AdminModule/Module::onBootstrap
class Module
{
public function onBootstrap($e)
{
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$controllerClass = get_class($controller);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
if ('AdminModule' === $moduleNamespace ) {
$controller->layout('layout/admin');
}
}, 100);
}
}
Not that this will set the layout to layout/admin. You would need to provide this key via your configuration:
'template_map' => array(
'layout/admin' => 'path/to/admin/module/view/layout/admin.phtml',
)
I'm trying to run application with Silex FW. I have similar source code as in example:
require_once __DIR__.'/silex.phar';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/views',
'twig.class_path' => __DIR__ . '/vendor/twig/lib',
));
$app->get('/hello/{name}', function ($name) use ($app) {
return $app['twig']->render('hello.twig', array(
'name' => $name,
));
});
$app->run();
But I'm getting this error:
Fatal error: Class 'Twig_Environment' not found in phar:///var/www/silex/silex.phar/src/Silex/Provider/TwigServiceProvider.php on line 40
Stack trace:
1. {main}() /var/www/silex/index.php:0
2. Silex\\Application->run() /var/www/silex/index.php:20
3. Silex\\Application->handle() phar:///var/www/silex/silex.phar/src/Silex/Application.php:396
4. Symfony\\Component\\HttpKernel\\HttpKernel->handle() phar:///var/www/silex/silex.phar/src/Silex/Application.php:411
5. Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:72
6. call_user_func_array() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:128
7. {closure}() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:128
8. Pimple->offsetGet() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:15
9. {closure}() phar:///var/www/silex/silex.phar/vendor/pimple/pimple/lib/Pimple.php:81
10. Silex\\Provider\\{closure}() phar:///var/www/silex/silex.phar/vendor/pimple/pimple/lib/Pimple.php:120
This problem was also posted on GitHub.
Solution is to use Composer and autoload.php.
With that approach, your twig.class_path probably needs to be vendor/twig/twig/lib (extra twig directory) ...
But twig.class_path is actually unnecessary, with composer, which is the better approach (as kuboslav notes).
I'm using Drupal 6 to run a gallery I've created. I need to take a parameter from the AJAX request lets say "food" and pass that argument to a view I've created (Views 2) where "food" is a taxonomy term that I am using to get the data I want in return. Everything is working just fine and in my module's method for loading the view I can load the entire view because in the settings you have 'if no argument get all values', but I can't seem to pass arguments to it. Here is the method...
function ajax_methods_menu()
{
$items = array();
$items['admin/settings/ajax_methods'] = array(
'title' => t('AJAX Methods settings.'),
'description' => t('Define settings for the AJAX Methods'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_methods_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM
);
$items['gateway'] = array(
'title' => 'AJAX Gateway',
'page callback' => 'ajax_methods_get_items',
'type' => MENU_CALLBACK,
'access arguments' => array('access content')
);
return $items;
}
function ajax_methods_get_items($args)
{
$content = views_get_view('All_Images');
return drupal_json(array('status' => 0, 'data' => $content->preview('default')));
exit;
}
In looking at the documentation views_get_view() doesn't seem to allow for arguments although I believe they are being passed to my ajax_methods_get_items() method. Thanks for reading!
Got it figured out, I needed to add
return arg(1);
seems to be working pretty well.