I have a views page that contains a listing of one of my content type. I used views-view-list--<name of my view>.tpl to theme the page. However, the region/blocks that I defined are not displaying. In other pages it works fine, but on the views page it does not. I'm trying to display a user login block in my defined region.
Please tell me how to access my user login block or my region to display on my views.
Your help is greatly appreciated. I'm using drupal 6 by the way.
Best regards,
Think i ran into something similar yesterday. I was trying to print a region, for example
<?php print $footer ?>
but inside a tpl file that came from views - and for whatever reason, it doesn't output the region from one of the views tpl files.
I used this code:
<?php print theme('blocks', footer); // change "footer" to the name of your region ?>
As I am writing this, a safer and maybe recommended way in D7 would be:
<?php
$region = block_get_blocks_by_region('footer') //first define the block;
print render($region) // then print the block;
?>
I tried #Garry but I got some errors back from Drupal. Please see here
Hope this helps someone down the line.
Any page in drupal have page template based on url or content type . So you have to create right page template for your page where views page/block to be displayed. I'm assuming that you are using page template based on url
This worked for me, except the syntax above needs semi-colons after (); for example print render($region); otherwise thank you for this answer
This is how the snippet will work for Drupal 7 with Bootstrap - HTML tags, considering that the 'billboard' region host an ad:
<aside class="col-xs-0 col-sm-12 role="banner">
<?php
$region = block_get_blocks_by_region('billboard');
print render($region);
?>
</aside>
Related
I'm looking to divide up my page into smaller sections for ease of organising my content. Other websites I've seen have used the system of having the main page url then a question mark and the next page name after it (eg. www.website.com/page.php?secondpage)
For what I want to achieve, see an example here (under collecting, current, etc). For my current page, see here.
Thanks for your help!
you can try like this in your html
a href="page.php?collections">collections
in your php code, you can write
<?php if($_SERVER["QUERY_STRING"] == 'collections'){ ?>
//second page code goes here
<?php } ?>
Sorry if this is a nooby question, but I have the following problem:
I have some sort of a Documentation as a multiple webpages. I created a basic navigation bar on the left of the screen using a tutorial... To be able to mark the active link every page has its own unique navigation adding it's own link to a specific div class.
The problem is that if I wanted to add another page to my collection I would have to add the link in every html document.
I know that there is a possibility to include other pages Php code to have one navigation document, but I have no idea on how to achieve that the current page is getting highlighted.
I would appreciate any help.
If you want to have your navigation on a separate file it is completely possible and is actually preferred.
Use any of the following:
require
include
require_once
include_once
So let's say your navigation HTML is located at nav.php you would do something like:
<html>
<head><title>My Awesome Website</title></head>
<body>
<div id="nav-wrapper">
<?php
include_once("nav.php");
?>
</div>
<div id="contents">
<h1>Hello World!</h1>
</div>
</body>
</html>
If you update your navigation in the future you will only need to update one file (nav.php).
So if you want to make a new function please read this:
http://php.net/manual/en/functions.user-defined.php
There is full info how to create function.
Pass to function what page is active you can just simply in this way:
function menu($active)
{
echo $active;
}
menu($active);
It's hard to say more, because you didn't show us anything, a construction of HTML or PHP. Please read linked above tutorial. I think it will be enough in this stage of PHP learn.
Because of Grzegor J I found this Stackoverflow question which pretty much solves my problem.
Thanks to everyone for trying.
Long time reader, first time poster :)
I'm just embarking on my first Cake app so hopefully you guys can help me on my way.
First question is about extending/including views. I realise the way the layouts/view work is to prevent code having to be repeated, but I can't get my head around how to set up what I want to do without some repetition.
My page layout consists, apart from header and footer, a left nav bar which I want Controllers to add themselves to if appropriate, and a top nav bar which will be populated by appropriate pages within the current controller.
I tried creating a view block from within the controller but it didn't work, I'm a bit stumped.
Here's what I have:
My default layout includes the sidebar, currently just hardcoded, and the content:
Layout default.ctp
<!DOCTYPE html>
<html>
<head>.....</head>
<body>
...
<div id='leftnav'>
This is where I want my left nav
I want controllers to be able to add themselves
here.
</div>
<?php echo $this->fetch('content'); ?>
</body>
</html>
Then my /Customer/index view:
View index.ctp
<?php $this->extend('common'); ?>
<h1>Customers</h1>
.... do stuff with customers .....
Which extends my /Customer/common view to bring in the top nav bar, each view has to include this extend line, it would be nice not to have to if there's a different way of doing this.
At the moment, the links are just fixed but I'd like the controller to be able to create these options.
View common.ctp
<?php
echo $this->Html->Link('index', "index")." ";
echo $this->Html->Link('find', 'find')." ";
echo $this->Html->Link('add', 'add')." ";
echo $this->Html->Link('details', 'details');
echo $this->Session->flash();
echo $this->fetch('content');
?>
Appreciate your help cheers! :D
I think you should just be able to put those links in your layout file. But you may have to re-write them as "$this->Html->link("Index",array("controller => $controller","action" => "index");" etc.
To get the current controller within the layout file you can say "$controller = $this->params['controller']".
right, after searching around I think I found a good way of doing at least one of these things.
For the top nav, where the links will be populated by the controller, I'll pass an array from the controller to view. Then, instead of having an ->extend in every view I'll create an element to turn the array into a nav bar, and ->fetch this in the layout.
This leads me onto my next question....
How much code is ok in a CakePHP Layout?
Hi you can use Cake PHP HTML Helper
https://book.cakephp.org/3/en/views/helpers/html.html#creating-links
echo $this->Html->link('Users List', ['controller' => 'Users','action' => 'index']);
Output will be look like this:
Users List
I'm adding some pages to default layout editor in SE4. What I do is just adding pages to core_pages table and editing core_content table to add a main container and a middle/right two columns layout. Everything works fine, but now I'm adding default Create Video page (videos_index_create) and I got some problems.
When I add this page via sql, I can obviously see and edit page layout by default layout editor. Actually, when I save changes these don't reflect to live page. If I go to the controller (Video/controllers/IndexController.php) and add
$this->_helper->content->setNoRender()
live page displays right sidebar and middle content, but with
$this->_helper->content->setEnabled()
it shows only the default video upload form.
So I edited create.tpl here
<?php if (($this->current_count >= $this->quota) && !empty($this->quota)):?>
<div class="tip">
<span>
<?php echo $this->translate('You have already uploaded the maximum number of videos allowed.');?>
<?php echo $this->translate('If you would like to upload a new video, please delete an old one first.', $this->url(array('action' => 'manage'), 'video_general'));?>
</span>
</div>
<br/>
<?php else:?>
<?php echo $this->form->render($this); ?>
<?php endif; ?>
Changing the else deleting the echo statement and adding a simple echo 'foo';. Now, live page shows properly my layout (middle+right) with default content ("foo").
I figured thus that the issue is about this line in controller:
$this->view->form = $form = new Video_Form_Video();
but I can't go further… this custom form class (Video/Form/Video.php) seems nothing special, I can't really figure out why its rendering crushes default layout render.
Any social engine expert right here to help me? :)
If its a Zend_Form I am pretty sure you should be doing:
<?php echo $this->form;?>
In your view not call render yourself.
If it is NOT a Zend_Form please post the code for the form it probably has some css or whatnot breaking your layout.
I have a custom CMS here entitled phpVMS, and I want to exclude a piece of code, a banner for a single page. phpVMS is steered using templates, for instance, the main template that codes the general layout for all pages is entitled layout.tpl. So, like I said, this displays whatever is in the template, on all of the pages. I have however created a special control panel, and therefore require to exclude the banner, because it slightly destroys the theme of it. Is there any PHP code that excludes a piece of code on a single site? I need to remove a single div...
<div id="slideshow"></div>
...on a single page.
Basically, I could create a new template but this is a very long winded and unefficient way within this CMS, and the final result isn't that great - because I can't reinclude the mainbox div which is the box defining the content on the centre white bit of the theme - it's already in the layout.tpl.
I hope you can somehow help me, hope I've included enough information there.
Thanks.
I don't think you can do what you're asking in PHP, but you might be able to do this on the client-side, by either hiding the div (CSS display:none) or by removing it with JavaScript. You might be able to do something like:
<?php
include("layout.tpi");
if (condition)
{
// Javascript:
echo "<script>document.getElementById('slideshow').style.display = 'none';</script>";
// OR jQuery:
echo "<script>$('#slideshow').hide();</script>";
}
?>
If you use a variable to determine you don't want to include the div, you could do this:
<?php if ($include) { ?>
<div id="slideshow"></div>
<?php } ?>
OR
<?php
if (!$include)
echo "<!--";
?>
<div id="slideshow"></div>
<?php
if (!$include)
echo "-->";
?>
EDIT: Obviously, there is no good reason to use the second method. The second method will only comment out the HTML so it will still show up in the source.
I'm not sure if this is what you are looking for, but seems simple
<?
$template = true;
if($template) {
?>
<div id="slideshow"></div>
<?
}
?>
On the template, you could have some code that reads:
if($_SERVER['PHP_SELF'] == /*control panel file*/) {
//exclude
}else{
//include
}