CakePHP 3.x Sidebar is not showing any content - cakephp

I was trying create a left side menu bar. I used the following code in my layout file Templates/Layout/admin.ctp
// Create the sidebar block.
$this->start('sidebar');
echo $this->fetch('sidebar');
echo $this->element('sidebar/left_menu');
$this->end();
But the sidebar is not showing in the page. The Left menu sidebar file is located at Templates/Element/Sidebar/left_menu.ctp
Any help will be appreciated.

There are two things I can point out:
The default directory for templates is src/Template and not Templates
As you are starting the block, fetch('sidebar') will return empty. Try putting it after the end of the block
// Create the sidebar block
$this->start('sidebar');
echo $this->element('sidebar/left_menu');
$this->end();
// Display the sidebar
$this->fetch('sidebar');

Related

Drupal 7 custom logo in page.tpl.php not displaying on all pages

I have a Drupal 7 site with a custom sub theme based on Zen. I have a custom logo that I placed in the page.tpl.php header div. The problem I'm having is that the logo only shows up on the first "main" pages, but not "subpages". Excuse my terminology here trying to explain this. What I mean by subpages is any page that is further down the chain or occurring after the first forward slash. Below is an example of what I mean by "main" pages and "subpages". All these "main" pages are directly after the first slash after the website name. The logo doesn't show up on any pages that occur after these main pages (subpages). All my pages are made using the Pages module, however, the subpages have a path using %term, for example /support/%term or products/%term.
What am I missing and what do I need to do to make my logo in page.tpl.php show up on all pages of my site? Am I supposed to create a new page.tpl.php file for the pages using /%term?
Main pages - logo shows up:
mysite.com/about
mysite.com/products
mysite.com/support
mysite.com/contact
Sub pages - logo doesn't show up:
mysite.com/products/product1
mysite.com/support/product1-support
If I understand you correctly, the quick fix for that is to make sure your logo's path starts with '/', like so:
<img src="/sites/all/themes/customZen/images/logo.png" />
But then if path of the theme changes everything will break, so don't do this.
If you place the logo using CSS as a background, use relative URL (it is relative to the path of .css file)
Or you can do something like this in your page.tpl.php:
<img src="<?php url($directory . '/images/logo.png'); ?>" />
$directory is the directory the template is located in, e.g. sites/all/themes/customZen.
Full list of page.tpl.php variables can be found here: https://api.drupal.org/api/drupal/modules%21system%21page.tpl.php/7.x
Did you solve this?..Well, if you didn't, try with this in your page.tpl.php paste this:
<img alt="" src="<?php echo drupal_get_path('theme', 'customZen');?>/images/logo.png">
Good luck!

hide right sidebar on specific pages in drupal

I want to remove the sidebar from the specific page and all its subsequent pages in Drupal 7
My code is mention below.code is in mytheme_preprocess_node(&$variables) function
if ($variables['type'] === 'project'){
$node = $variables['node'];
if($node->type=='project'){
//print_r($node);
echo $node->type;
unset($page['sidebar_second']);
}
why don't you create a tpl file for that specific content type and remove the sidebar from there ? just an idea
Try restricting the block in Blocks UI or with the Context module.
You can restrict that sidebar content in admin panel itself. login as admin and configure that sidebar block to display only on perticular url.

Why is the region in Drupal blank?

I my .info file I have this:
regions[footermenu] = Footer Menu
The region--footer.tp.php has this:
<?php
print render($page['footermenu']);
?>
I've placed a menu block in the "Footer Menu" (it shows up under structure->blocks). However, it's blank. If I place the block in region I know works the menu content is seen fine. Any idea why the region wouldn't see the block?
It may just be a typo in your question, but check that the template's file name ends with '.tpl.php'.
The code that triggers the rendering of your region, namely <?php print render ($page['footermenu']); ?>, goes in 'page.tpl.php', which in turn will render 'region.tpl.php' (or 'region--footermenu.tpl.php' in your specific case).
You will have to clear the theme's cache when you add a new template file. That can be done simply by visiting your theme's settings page.

Load layout element based on view in CakePHP

I have a sidebar defined in my main layout which most of the time will display the login form. After the user is logged in I need to remove that form and replace it with user data. I also need to change that sidebar when viewing the support section to show the sub-sections.
Do I need to move the element loading to each view or is there another way?
Thanks in advance,
Denis
Bottom line is you're gonna need an if($supportpage){} elseif($loggedin){} else{} block. If you don't want to put it in your layout file you could create an element for each option and then set() the correct one from the app_controller:
if ($supportpage) $sidebar = 'support';
elseif ($loggedin) $sidebar = 'loggedin';
else $sidebar = 'notloggedin';
$this->set(compact($sidebar));
And then put $this->element($sidebar) in your layout.

Jquery mobile ui-btn-active in navbar

I've been trying to get this to work for 4 days now, with no luck.
I have a very simple jquery mobile app.
The app has a header, content and footer.
The footer is being generated dynamically on the 'pagecreate' event because it is always the same and I don't want to have its HTML in every page.
So I do something like this:
$(document).delegate('[data-role="page"]', 'pagecreate', function (e) {
DrawHeader($(this));
DrawFooter($(this));
SetFooterEvents($(this));
SetActiveFooter($(this));
});
DrawHeader() and DrawFooter() simply prepent the header div to the page and append the footer div.
SetFooterEvents() sets the onclick events of the footer navbar buttons and SetActiveFooter() is SUPPOSED to set the ui-btn-active to the current active footer link.
To do this, I've added the data-active-footer attribute to the page div and the data-name attribute to the navbar elements. I'm searching for the current element according to the data-active-footer in the page and apply the ui-btn-active class.
function SetActiveFooter(page) {
page.children('div[data-role="footer"]')
.find('a[data-name="' + page
.attr("data-active-footer") + '"]').addClass("ui-btn-active");}
So far so good.
Now, say I've changed to a page and the navbar is lit (it has successfully recieved the ui-btn-active class), and I'm clicking on the previous page, the lit item in the navbar doesnt change back!
If i click on the the page again (ie: changed to second page [corrent lit], changed back to first page [second page is still lit], then clicked on first page again) it does light the navbar button.
What I found out was that jqm also changed the navbar of the previous page when I'm changing the navbar of the current page in the 'pagecreate' event.
I've tried to overwrite this behaviour using the 'pageshow' event, that is, trying to apply the ui-btn-active class to the current element in the navbar but the problem is that $(this) and e.currentTarget objects in the 'pageshow' event DO NOT CONTAIN THE FOOTER ELEMENT!!!
$(".ui-page").live('pageshow', function (e) {
alert($(this).children('div').length); // returns 2!
alert($(this).children('div[data-role="footer"]').length); //returns 0
alert($(e.currentTarget).children('div').length); // returns 2!
alert($(e.currentTarget).children('div[data-role="footer"]').length); //returns 0});
Any ideas?!
Thanks.
Before delving into more detail, please try adding .ui-state-persist together with .ui-btn-active
This makes sure active buttons stay active when you changePage and the footer is the same. Also make sure, all your footers have the same data-id attribute.
On a sidenote: check the latest blog post about upcoming features for jqm 1.1 - it will include a fetch link utility, which allows to ajax-update portions of a page. So you could use this functionality to grab and insert a footer on every page. I'm trying the same right now with a login form, which I need on every page.
Have you tried "ui-state-persist"?
<div data-role="navbar" data-iconpos="top">
<ul>
<li>Home</li>
<li>Favorite</li>
</ul>
</div>
I still dont know why but jqm moves the footer from page to page, eventhough I assign a new footer to each page.
Maybe because I set the same ID to all of them.
Anyhow, I used this workaround to solve the problem:
On the 'pagebeforeshow' event, I set the button I want active to all the footers in the documents. I've set a special data-name attribute to each navbar button, I give it the 'ui-btn-active' class after removing it from the rest of the items.
var $footers = $(document).find('div[data-role="footer"]');
$footers.find('a').removeClass("ui-btn-active");
$footers.find('a[data-name="' + page
.attr("data-active-footer") + '"]').addClass("ui-btn-active");

Resources