(Using Adaptive Theme) I want a new and custom user login page. So, put this code in my template.php:
function mythemename_theme() {
$items = array();
// create custom user-login.tpl.php
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'mythemename') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'mythemename_preprocess_user_login'
),
);
return $items;
}
Changed mythemename to my custom theme name. And created user-login.tpl.php files and put this code:
<?php
print drupal_render($form['name']);
print drupal_render($form['pass']);
print drupal_render($form['form_build_id']);
print drupal_render($form['form_id']);
print drupal_render($form['actions']);
?>
Lastly, cleared my site cache. But when i click mysite.com/user login page not changed.
Where the error am I doing? How can I solve this problem?
Try putting this in template.php, change mythemename to theme name, and flush the cache.
function mythemename_theme($existing, $type, $theme, $path){
$hooks['user_login']=array(
'render element'=>'form',
'template'=>'templates/user-login',
);
return $hooks;
}
Then in templates/user-login.tpl.php insert:
<?php
print render($form['name']);
print render($form['pass']);
print render($form['form_build_id']);
print render($form['form_id']);
print render($form['actions']);
?>
or
<?php print drupal_render_children($form) ?>
Related
I have a table on my database from where I get some slug texts:
art_and_culture
business_and_financial
auto_and_moto
and display on my website through
<?php echo lang($slug_from_database); ?>
I use this method as LanguageSwticher:
multi-language-support-in-codeigniter
So in My_Controller.php I have in construct:
$this->categories_list = $this->categories_model->entries();
$list_categories['categories'] = $this->categories_list;
$this->data['sidebar_categories'] = $this->load->view('blocks/sidebar_categories', $list_categories, TRUE);
and all the categories are available on all pages from my website. The problem is when I send to the view the categories, the language is not set from the LanguageLoader.php controller witch is initialised in hooks.php (see the link example). If no language no text on echo $slug_from_database. How do you suggest to do?
I found one solution:
Created:
public function LanguageLoader() {
$site_lang = $this->session->userdata('site_lang');
if ($site_lang) {
$this->lang->load('message',$this->session->userdata('site_lang'));
} else {
$this->lang->load('message', $this->config->item('language'));
}
}
in MY_Controller.php
and call it in the constructor: $this->LanguageLoader();
and delete
$hook['post_controller_constructor'] = array(
'class' => 'LanguageLoader',
'function' => 'initialize',
'filename' => 'LanguageLoader.php',
'filepath' => 'hooks'
);
from hooks.php so now I load the language in controller`s construct not with hook.
I have 3 websites.
I created custom php page with site header and footer.
The same php file is used in all 3 sites.
In two sites it works perfectly but in the 3rd site the title of the page shows 404 error.
I cannot figure out why this is happening.
I checked .htacccess file and tried to match them but it seems ok too. I have been looking for an answer on Prestashop forums but could not find anything.
In the following two sites, if you look at the browser tab the title is fine.
http://malverncomputerservices.com.au/payment.php
https://i.net.au/payment.php
In this 3rd site however, the title shows 404 error. The page functions properly but always has error on top of the page. I don't know how this happened as the php files are just copies of the original.
http://toorakcomputerservices.com.au/payment.php
I found the solution and it works for me. Create php file anywhere either in root folder or inner folder and paste the below code. Tested with 1.6 version.
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php';
$current = getcwd();
class ContentPageCutomized extends FrontController
{
public function initContent()
{
parent::initContent();
}
public function displayHeader()
{
$hook_header = Hook::exec('displayHeader');
if ((Configuration::get('PS_CSS_THEME_CACHE') || Configuration::get('PS_JS_THEME_CACHE')) && is_writable(_PS_THEME_DIR_.'cache'))
{
// CSS compressor management
if (Configuration::get('PS_CSS_THEME_CACHE'))
$this->css_files = Media::cccCSS($this->css_files);
//JS compressor management
if (Configuration::get('PS_JS_THEME_CACHE'))
$this->js_files = Media::cccJs($this->js_files);
}
$this->context->smarty->assign(array(
'meta_title' => 'My title'
));
// Call hook before assign of css_files and js_files in order to include correctly all css and javascript files
$this->context->smarty->assign(array(
'HOOK_HEADER' => $hook_header,
'HOOK_TOP' => Hook::exec('displayTop'),
'HOOK_LEFT_COLUMN' => ($this->display_column_left ? Hook::exec('displayLeftColumn') : ''),
'HOOK_RIGHT_COLUMN' => ($this->display_column_right ? Hook::exec('displayRightColumn', array('cart' => $this->context->cart)) : ''),
'HOOK_FOOTER' => Hook::exec('displayFooter')
));
$this->context->smarty->assign(array(
'css_files' => $this->css_files,
'js_files' => ($this->getLayout() && (bool)Configuration::get('PS_JS_DEFER')) ? array() : $this->js_files,
'js_defer' => (bool)Configuration::get('PS_JS_DEFER'),
'errors' => $this->errors,
'display_header' => $this->display_header,
'display_footer' => $this->display_footer,
));
$layout = $this->getLayout();
if ($layout) {
if ($this->template) {
$template = $this->context->smarty->fetch($this->template);
echo 'might be';
} else {
// For retrocompatibility with 1.4 controller
ob_start();
$this->displayContent();
$template = ob_get_contents();
ob_clean();
}
$this->context->smarty->assign('template', $template);
$this->smartyOutputContent($layout);
} else {
Tools::displayAsDeprecated('layout.tpl is missing in your theme directory');
if ($this->display_header) {
$this->smartyOutputContent(_PS_THEME_DIR_.'header.tpl');
}
if ($this->template) {
$this->smartyOutputContent($this->template);
} else { // For retrocompatibility with 1.4 controller
$this->displayContent();
}
}
}
public function init()
{
parent::init();
}
public function displayContent()
{
?>
//Start your html content here
Your content here
//End your htmlcontent here
<?php
}
}
$controller=new ContentPageCutomized();
$controller->init();
$controller->setMedia();
$controller->initHeader();
$controller->displayHeader();
$controller->initContent();
?>
I created a content type called custom content type..now I want to override the content type with the form id.I included bartik_theme in template.php and custom-content-type-node-form as my form id and I created custom-content-type-node-form.tpl.php in template in bartik..but am unable to override.I try to use dpm() function to print array structure that also not working.thank you in advance..
I included this in template.php
function bartik_theme() {
return array(
'custom_content_type_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'templates/custom-content-type-node-form',
'render element' => 'form'
),
);
}
I created custom-content-type-node-form.tpl.php in template folder
<?php
dpm($form);
hide($form['body']);
print drupal_render_children($form['field_custom_image']);
print drupal_render_children($form['title']);
print drupal_render_children($form);
?>
That's because your custom theme implementation is not in the theme hook suggestions array.
Use "template_preprocess_page" hook to add a suggestion to the the hook suggestions array :
function yourtheme_preprocess_page(&$vars) {
//your checks here ...
$vars['theme_hook_suggestions'][] = 'custom_content_type_node_form';
//...
}
However if you want to change form element I suggest to use "hook_form_alter" or "hook_form_FORM_ID_alter" hook.
i've been using and studying Collin Williams template plugin (http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html#manipulation) and i've already posted this issue on CI's forum but i think the last post was last year maybe its not being monitored by Colllin or wat but i guess i'll just have to post this here maybe you guys can help.
Original Post on CI Forum
Hello Collin,
I’ve been studying your template plugin lately, as i was following your guide,
i came across this line of code
$data = array('name' => 'John Smith', 'birthdate' => '11/15/1950');
$this->template->write_view('content', 'user/profile', $data, TRUE);
it was a bit confusing whether in the view files, like
mymastertemplate.php for example, how do i accessthe $data array, does
it have to be $content defined by that first param. a region, or by
$name and $birthdate? ... cuz’ it says there $content will display the
data array? its a bit confusing. Hope you could enlighten me.
Basically thats my problem.
On Template.php library we can see function write_view(). Now, focus on $data = NULL. Now then finds a file of existed data on APPPATH.'views/'.$suggestion.'.php' so I think that $args[0] should be a file which is loaded and break it, than loaded a view template on $data.
function write_view($region, $view, $data = NULL, $overwrite = FALSE)
{
$args = func_get_args();
// Get rid of non-views
unset($args[0], $args[2], $args[3]);
// Do we have more view suggestions?
if (count($args) > 1)
{
foreach ($args as $suggestion)
{
if (file_exists(APPPATH .'views/'. $suggestion . EXT) or file_exists(APPPATH .'views/'. $suggestion))
{
// Just change the $view arg so the rest of our method works as normal
$view = $suggestion;
break;
}
}
}
$content = $this->CI->load->view($view, $data, TRUE);
$this->write($region, $content, $overwrite);
}
In another way, $data should be as array which will response for View template data on Codeigniter library (standard view of CI: $this->CI->load->view(...))
$data = array('name' => 'John Smith', 'birthdate' => '11/15/1950');
$this->template->write_view('content', 'user/profile', $data, TRUE);
On template file '/user/profile.php' use as example:
HTML/PHP template file profile.php:
Your name: <?php echo $data["name"]; ?>
Your name: <?php echo $data["birthdate"]; ?>
And as I see, a CONTENT var must be an ARRAY due to documentation...
$template['default']['regions'] = array(
'header' => array(
'content' => array('<h1>Welcome</h1>','<p>Hello World</p>'), ### <----- AS EXAMPLE
'name' => 'Page Header',
'wrapper' => '<div>',
'attributes' => array('id' => 'header', 'class' => 'clearfix')
)
);
Regions must be defined as template, so if you didn't have header region that didn't work:
$template['default']['regions'] = array(
'header',
'content',
'footer',
);
!!!!!
Simply, he can't acces private access variable _ci_cached_vars which is stored data like $name. RELATED TOPIC: CodeIgniter shared data between calls to load->view
I'm using CakePHP to create a frontend UI for PowerDNS, using a MySQL backend. On the front page of the app I want to have a handful of widgets ('Quickly add a record', 'Quickly add a domain' etc.). One of the widgets I want is a paginated list of existing domains.
The index function in DomainsController.php looks like this:
public $paginate = array(
'fields' => array('id', 'name'),
'limit' => 25,
'order' => array( 'name' => 'asc' ),
'conditions' => array( "NOT" => array( "name LIKE" => "%.arpa" ) )
);
public function index() {
$domains = $this->paginate();
if ( $this->request->is('requested')) {
return $domains;
} else {
$this->set('domains', $domains);
}
}
I've created an element that looks like this:
<?php $domains = $this->requestAction('Domains/index'); ?>
<ol>
<?php foreach( $domains as $domain) :?>
<li>echo $domains['domain']['name']</li>
<?php endforeach; ?>
</ol>
<?php echo $paginator->numbers(); ?>
When I visit the front page, I get an 'Undefinied variable: paginator' error. I've tried using $this->Paginator->numbers() instead but that just gives me 'Undefined property: View::$Paginator'. Adding the 'Paginator' helper to PagesController.php doesn't help either - $this->Paginator becomes available but I get 'Undefined index: pageCount'.
Is it possible to do this kind of pagination from an element on home.ctp or am I going to have to do some custom JavaScript stuff?
EDIT
Now I'm getting somewhere: I changed my DomainsController index function to this:
public function index() {
$domains = $this->paginate();
$paginator = $this->params;
if ( $this->request->is('requested')) {
return compact( 'domains', 'paginator' );
} else {
$this->set('domains', $domains);
}
}
And added the following to the domainList.ctp element:
<?php
$result = $this->requestAction('Domains/index');
$domains = $result['domains'];
$this->Paginator->request = $result['paginator'];
?>
<ol>
<?php foreach( $domains as $domain) :?>
<li>echo $domains['domain']['name']</li>
<?php endforeach; ?>
</ol>
<?php echo $paginator->numbers(); ?>
$this->Paginator is now working properly and I can access all of its methods and properties and so on as normal. My problem now is that if I click on, say, '2', the browser navigates to /pages/home/page:2 but the domain list still shows page 1. Just need to figure out how to pass 'page:2' to the element. And AJAX-ify the whole thing so that I don't need to refresh the whole page.
Firstly, don't do this:
$domains = $this->requestAction('Domains/index');
It's expensive and not good practice and I'm not sure why you need to be doing it from your example.
Secondly, call your paginate like this:
$domains = $this->Paginate('Domain');
OK, I solved this problem, although my solution probably isn't very elegant.
DomainsController.php has a listDomains() function that looks like this:
public function listDomains() {
$domains = $this->paginate();
$paginator = $this->params;
if ( $this->request->is('ajax') ) {
$this->set( 'domains', $domains );
}
if ( $this->request->is('requested')) {
return array( 'domains' => $domains, 'paginator' => $paginator, 'paging' => $this->params['paging'] );
} else {
$this->set( 'domains', $domains );
}
}
home.ctp references an element called domainList.ctp. domainList.ctp, below, in turn uses requestAction() - I know, I know - to call the domainList() function above. Bequest the request is requested, an array containing the values of $domains and $paginator is sent back to the element.
domainList.ctp contains this code:
<?php
$result = $this->requestAction('Domains/listDomains', array('updateId' => 'domainList') );
$domains = $result['domains'];
$paginator = $result['paginator'];
$this->Paginator->request = $paginator;
$this->Paginator->options(array(
'update' => '#domainList',
'evalScripts' => true,
'url' => array('controller' => 'Domains', 'action' => 'listDomains', 'updateId' => 'domainList' ),
));
?>
Essentially what I'm doing here is manually re-populating $this->Paginator->request with the params that were originally sent to the DomainController's domainList() function. This lets me access the various paginator functions, like numbers(), prev() and next(), properly. It's a bit messy but guess what? It gets a little messier.
When you click on the links created by those paginator functions, the 'if ( $this->request->is('ajax') )' segment is executed and the div object on the page is updated with the contents of View/Domains/domainList.ctp instead of View/Elements/domainList.ctp. The contents of View/Domains/domainList.ctp is more or less the same as the corresponding element and the two have to be kep more or less syncronised. The difference is that we don't need to manually populate $this->Paginator:
<?php
$this->Paginator->options(array(
'update' => '#domainList',
'evalScripts' => true,
'url' => array('controller' => 'Domains', 'action' => 'listDomains', 'updateId' => 'domainList' ),
));
?>
Like I said, it's messy and inelegant but it worked for me. I'd be happy to know if anyone has a less kludgy way to do this.