Fetching common elements in admin layout - cakephp

I'm trying to fetch a common element from my admin.ctp layout
<?php echo $this->fetch('my_element'); ?>
This functions is working properly in my default layout but is returning an empty string if called from my admin layout.
I'm using admin routing prefixes.

Can you use this form:
<?php echo $this->element('my_element'); ?>

Related

cakephp 3 : How to add class in form button?

I have tried this line to add class in cakephp form button, but class is not showing in html
<?= $this->Form->button(__('Login',['class'=>'login-btn'])); ?>
How can I add class in button ?
I think your example doesn't work, because the __() Call shouldn't include the array for the options of the button. Please try the following:
<?= $this->Form->button(__('Login'),['class'=>'login-btn']); ?>
Have a try on this below:
<?php echo $this->Form->button('Login',['class'=>'login-btn']); ?>
A good reference here: Creating input elements
Update
__() is for internalization. Using this will look in to your localization file and output it's corresponding translation. In your case, you include the options inside __() which I think it will cause an error but if it didn't, it will look for it's translated version and also this means ['class'=>'login-btn'] is not considered as an option anymore.
it has to be inside an array : try this
<?= $this->Form->button(__('Login'),array('class'=>'login-btn')); ?>

Drupal 7 overriding node.tpl.php

I am trying to override the front page node, however after following the guide from the official site, it's not working.
Guide: https://www.drupal.org/node/1585528
I have taken node.tpl.php and renamed it to node--front.tpl.php and made changes to the layout, saved and cleared cache. The changes are not being displayed.
Now if I edit node.tpl.php directly it shows the changes, anyone know what I am doing wrong to override specific node templates?
EDIT:
I want to move the title below the image being displayed in the front page.
See below: Moving the title block under the content block, moves the title down as I want it to do, however how do I specify this for just the front page and not all nodes? (renaming node.tpl.php to node--front.tpl.php does not work as mentioned above)
In node.tpl.php: (title block)
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>>
<?php print $title; ?>
</h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
(content block)
<div class="content clearfix"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
To override the node template for particular node, you need to override the default node.tpl.php. For this copy the existing node.tpl.php file to node--{node_id}.tpl.php.
If you want to override the page template only for front page then you can create page--front.tpl.php file and copy the page.tpl.php file and then modify it as per your requirement.
Still you have issues, then use hook_preprocess_page() in template.php and use dpm() function to find the theme_suggestions that will give the sequence of execution of templates file.
you can use node-{nodeid}.tpl.php
It may help you.
Source: https://drupal.stackexchange.com/questions/39710/how-do-i-define-a-template-file-for-a-specific-node-id
Thanks
Samit K
samitkhulve.com

where to load javascript in a view page Cakephp

i am working on a Cakephp 2.x .. right now i am loading my js and css files like this
View/Layout/default.ctp
<?php echo $this->fetch('css'); ?>
<?php echo $this->fetch('script'); ?>
<?php echo $this->fetch('scriptBottom');?>
and in each view file i am doing this because there are some pages i am loading different css and js files
for example
View/users/index.ctp
echo $this->Html->script('libs/modernizr.custom',array('inline' => false));
$this->Html->css('reset3860.css', null, array('inline' => false));
echo $this->Html->script('libs/jquery-1.8.2.min', array('block' => 'scriptBottom'));
now the first problem i am facing right now is when i have to write js at the bottom of view page for example if i am submitting a form through ajax .. i can't write at the bottom of the index page ... because if i write there the js will go at the middle or center of the page so now what i do is i go the default.ctp and write there..
so i want to write at the bottom of the index page so it can easily managable and i can see it well what i am doing
the second question is what is the best way to manage all this ... or is there a way that i can make one file of cs and js ... in which there is only the css and js files are loaded ..and then i include that file in my default . ctp page
You should place scriptBottom block at the bottom of your layout, after content block:
<body>
<?php
echo $this->fetch('script');
echo $this->fetch('content');
echo $this->fetch('scriptBottom');
?>
</body>
And then in your views (notice - NO echo):
$this->Html->script(
'libs/jquery-1.8.2.min',
array('block' => 'scriptBottom')
);
$this->Html->scriptBlock(
"alert('Boom!');",
array('block' => 'scriptBottom')
);
here is very good concept and also i have applied in one of my application, it is working very well
it compatible with CakePHP 2.1, and packaged it as a plugin. And also upgraded the CSS compression from CSSTidy to the more recent and better maintained CSS Min.
The plugin is quick and easy to install. The installation instructions are somewhat long - but that's just to provide clarity.
for detail view you can refer Detail link Cakephp.org also you can see the plugin document and how to use it in your appliation

tag cloud from database

I store tags in a table which is entered by users of my site. So basically I just need to run,
<?php echo $thing->tags; ?>
and this will return all the tags for that thing. Right now it just spits out a list of the tags like "bananas apples fruit, blueberries", where the tags are both comma and space delimited. I know that in order to create a tag cloud I need to spit out the tags to a ul and then run a jquery script on the li's. I think if I can get my tags to appear in the form,
<ul>
<li>bananas</li>
<li>apples</li>
<li>fruit</li>
<li>blueberries</li>
</ul>
Then I will be able to write a jquery script to put each of these elements in little tag cloud boxes. But I don't know how to get the tags to appear in this form. When I echo the tags can I apply some php function which will do this for me?
UPDATE: I used preg_split,
<?php $tags=preg_split("/[\s,]+/", "$things->tags"); var_dump($tags);?>
And now they are listed in an array -- comma and space delimited. My only challenge now is to surround these elements of the array in li tags.
Okay, I figured this one out on my own. After creating the array as mentioned above, I used
<?php foreach ($tags as $row) : ?>
<li><? echo $row[0]; ?></li>
<li><? echo $row[1]; ?></li>
<li><? echo $row[2]; ?></li>
<? endforeach; ?>
etc.

how to select multiple entries from a auto complete box in cakephp?

I have an auto complete box which is populated with the list of users of the application. It is working fine with the box listing the users.
But I am able to select only one user. How to select multiple users from the list ?
And also how to save the selected user's names in a variable or an array?
EDIT
I am using the built-in auto complete feature of the CakePHP framework. This is the action in the controller which generates the auto complete text box.
function autoComplete()
{
$this->set('users',$this->User->find('all',array(
'fields'=>array('User.id','User.name'),
'conditions'=>array('User.name LIKE' => $this->data['User']['name'].'%'))));
$this->layout = "ajax";
}
This is the auto_complete.ctp file
<ul>
<?php foreach($users as $user): ?>
<li><?php echo $user['User']['name']; ?></li>
<?php endforeach; ?>
</ul>
And this is the view where I have the auto complete box:
<?php echo $form->create('User', array('url' => '/forms/share')); ?>
<?php echo $ajax->autoComplete('User.name', '/forms/autoComplete');?>
<?php echo $form->end('Share');?>
In the auto complete box, I am able to select only one user name. how can I select multiple users with a comma or space separator?
I don't think the AjaxHelper can produce a multi-selection auto-complete box, it's not what it's designed to do. I'm afraid you'll have to roll your own solution. Since you're already getting a nice list via Ajax that shouldn't be too much trouble.
If you want something like the Stack Overflow tag box you can probably get by by placing a few Javascript callbacks in the Helper, if you're looking for a checkbox based list you'll need to do your own.

Resources