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',
)
Related
It seems I have found the way to make WordPress default gallery pagination to work and to have control over URL forming: https://wordpress.stackexchange.com/questions/401034/pagination-with-wordpress-default-gallery But when gallery call is in post.
When gallery call is in page, it works only if URL is like this: domain.com/pagename/page/2/, domain.com/pagename/page/3/ etc. Trying to have a different URL ends up in stopping it to work.
The part of code handling pagination in functions.php:
// Pagination Setup
$current = (get_query_var('paged')) ? get_query_var( 'paged' ) : 1;
$per_page = 3;
$offset = ($current-1) * $per_page;
$big = 999999999;
$total = sizeof($attachments);
$total_pages = round($total/$per_page);
if( $total_pages < ( $total/$per_page ) ){
$total_pages = $total_pages+1;
}
// Pagination output
$output .= paginate_links( array(
'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => $current,
'total' => $total_pages,
'prev_text' => __('«'),
'next_text' => __('»')
) );
As long as I keep URL like this domain.com/pagename/page/2/ , other ways for 'base' also work:
'base' => get_permalink( $post->post_parent ) . '%_%',
'format' => 'page/%#%/',
And like this:
'base' => get_pagenum_link( 1 ) . '%_%',
'format' => 'page/%#%/',
But when I try some other URL scheme:
'base' => get_permalink( $post->post_parent ) . '%_%',
'format' => 'paging-%#%',
pagination stops working.
The filter with rewrite tag and rule:
add_filter('init', 'post_gallery_add_rewrite_tag_rule_2022');
function post_gallery_add_rewrite_tag_rule_2022() {
add_rewrite_tag('%current%','(.+)');
add_rewrite_rule('(.+)/paging-/?([0-9]{1,})/?$', 'index.php?name=$matches[1]&paged=$matches[2]', 'top');
}
It seems like add_rewrite_rule is not functioning when gallery call is in page? Or what? Any ideas?
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'
),
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'
),
));
I am working with Drupal 6 and creating a module that involves a form submission. I opted to use the #type "radio" as it allows me to dynamically create a table (which is necessary for display purposes).
I am outputting the returned values of each radio I have selected in the image. However, whenever I submit the form, the #default_value is returned rather than the #return_value.
Here is my code as well as a screenshot of the page. Any help is greatly appreciated!
======Image of the Problem Here=======
function peereval_survey(&$formstate, $numStudents)
{
drupal_add_css(drupal_get_path('module', 'peereval') .'/peereval.css');
for ($rowNum = 1; $rowNum <= $numStudents; $rowNum++)
{
for ($colNum = 1; $colNum <= 5; $colNum++)
{
if ($rowNum == 1)
{
$form['v' . $colNum]['u' . $rowNum . ',v' . $colNum] = array
(
'#prefix' => "<tr><td>",
'#suffix' => "</td>",
'#type' => 'radio',
'#title' => t($rowNum . ', ' . $colNum),
'#name' => 'u' . $rowNum,
'#default_value' => 0,
'#return_value' => $colNum,
);
}
else if ($rowNum == 5)
{
$form['v' . $colNum]['u' . $rowNum . ',v' . $colNum] = array
(
'#prefix' => "<td>",
'#suffix' => "</td></tr>",
'#type' => 'radio',
'#title' => t($rowNum . ', ' . $colNum),
'#name' => 'u' . $rowNum,
'#default_value' => 0,
'#return_value' => $colNum,
);
}
else
{
$form['v' . $colNum]['u' . $rowNum . ',v' . $colNum] = array
(
'#prefix' => "<td>",
'#suffix' => "</td>",
'#type' => 'radio',
'#title' => t($rowNum . ', ' . $colNum),
'#name' => 'u' . $rowNum,
'#default_value' => 0,
'#return_value' => $colNum,
);
}
}
}
$form['numStudents'] = array
(
'#type' => 'hidden',
'#value' => $numStudents
);
$form['submit'] = array
(
'#prefix' => '<div id="submit">',
'#suffix' => '</div>',
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function peereval_survey_submit($form, &$form_state)
{
$form_state['redirect'] = 'peereval/1/5/1';
drupal_set_message("hi" . $form_state['values']['u1,v1'] . $form_state['values']['u2,v2'] . $form_state['values']['u3,v3'] . $form_state['values']['u4,v4'] . $form_state['values']['u5,v5']);
return $form;
}
The following variables contained my data:
$form_state['clicked_button']['#post']['u1'],
$form_state['clicked_button']['#post']['u2'],
$form_state['clicked_button']['#post']['u3'],
$form_state['clicked_button']['#post']['u4'],
$form_state['clicked_button']['#post']['u5'].
Big thanks to Adam Balsam for helping me find this!
After reviewing some posts here and elsewhere, I still can't seem to manually add a select field to the profile. (I need the select list to be populated with a SQL query, not supported with core profile module.)
So far, I am trying two different ways: hook form alter ($form_id == 'user-register' & hook user ($op == 'register') -- but I can't even get the field to appear in the registration form.
function accountselect_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'register'){
$fields['account_select'] = array(
'#type' => 'fieldset',
'#title' => t('Your Security Question')
);
$fields['account_select']['account_name'] = array(
'#type' => 'select',
'#default_value' => 'Select',
'#description' => t('Select a verification question in case you forget your password'),
'#options' => array(t('Select One'),
t('Where you attended Elementry School'), t('Your Best Man'))
);
return $fields;
}
Here is the hook form alter attempt
function accountselect_form_alter(&$form, $form_state, $form_id){
if($form_id == 'user-register') {
$form['account_select']['account_name'] = array(
'#type' => 'select',
'#title' => t('Account'),
'#description' => t('Enter the account to which the contact belongs.'),
'#options' => array(t('Account1'),t('account2'), t('account3')),
'#default_value' => $edit ['Account']
);
}
return $fields;
}
Sorry Guys, the code here is correct. I did a little debugging when the module was first enabled. I thought I had successfully fixed the problem, but what really happened is that the module became disabled. So, no matter what was in there, it would have had no effect....
No worries, I've punched myself in the face for the stupid question....