i have a yii site that contains main layout. in this main layout file i have a piece of code that prints the current page's output. here it is:
<?php echo $content; ?>
so the question is how to make other regions on the page?
for example i want to have a banners block, that will be printed out depending on the page. is there a way to write something like
<?php echo $banners; ?>
inside the main layout and this region will be filled with some data returned from a controller?
thanks/
Example
add main layout:
<?php $this->renderPartial('/site/_banners'); ?>
create view file (protected/views/site/_banners.php):
write banners code...
Related
I have an HTML template which I am trying to convert into PHP for WordPress.
The homepage has been converted and is shown properly. Next, the menu in navbar is about, the page that needs to be converted in PHP.
I have just added get_header() at the top and get_footer() below. In between these two I have added the HTML content for my entire page.
Then I tried to provide the link for the menu that I created, but the content of about page is not visible.
Do I need to add any other line for that page apart from get_header and get_footer? Or is something wrong with the link?
Clearly I can't understand what your are trying to say. I think you want to create a page that will show your about menu content.
So in your theme directory create a page name page.php and use get_header(); in first and below get_footer and where you want to show page content write the_content();. like this
<?php
get_header(); ?>
<div><?php the_content(); ?></div>
<?php get_footer(); ?>
after that follow the url of # Sajid Anwar. because for dynamic data you have to create pages(home,about etc) from wordpress dashboard and in menu section add these pages as navigation menu to menu.
Before I made the switch to Drupal (previously just static HTML), I had a div title in my header that changed depending on what page the user was on using the following code:
ABOUT PAGE
<?php
$title = "ABOUT US</span>";
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/header.php";
include_once($path); ?>
The reason this worked, however, was because I was using static HTML... which means I had every page set to use its own Index.PHP, located at (for the About page, for example) public_HTML/about/index.php. Therefore, I could edit each page individually to my liking by editing its respective Index file...
Now, with Drupal.. instead of having so many Index.PHP files like I did before (which was messy IMO...), I want to have every page use the same page.tpl.php (with the exception of the front page, which uses page--front.tpl.php).
Can I somehow modify the above PHP code to display a different title using IF statements depending on what page the user is on?
For example... (I have no idea how to PHP code so this is just to give you experts an idea of what I would want..)
Ifpage=about, $title=About Us;
Ifpage=contact, $title=Contact Us;
Could this code all be in the same page.tpl.php?
Thank you so much!
Drupal 7 has a title field for each content type. Why don't you use that?
It shows by default and you can change it for every node.
It is this code in your template file.
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<h1 class="title" id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>
<?php print render($title_suffix); ?>
$title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
$title: The page title, for use in the actual HTML content.
$title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
See https://api.drupal.org/api/drupal/modules!system!page.tpl.php/7 for all the variables available in your page.tpl template file.
If you want to style one part different from the other you could use an extra field for it.
Or if you need to do something with the value (I wouldn't suggest this!!!).
switch ($title) {
case "About Us":
// Do something with the title
break;
case "Contact Us":
// Do something with the title
break;
case 2:
// Do something with the title
break;
}
Here's a simple approach:
Add a new field for the content type
Call it title2
Render the two fields
Use css to inline align them and add styling
Here was my solution since I am unable to position a Drupal-based title block right next to a non-Drupal based logo DIV..
I created a div called .headertitle and positioned/styled it how I want.
My header.php is an PHP include file which is called by each page and the headertitle has a PHP condition..
<?php if(empty($headertitle)) $headertitle = "ASK REAL QUESTIONS, <br><span class='white'>GET FREE ANSWERS.</span>";
echo $headertitle; ?>
That way, if no text is declared for the .headertitle, it takes the default form of "ASK REAL QUESTIONS, GET FREE ANSWERS."
...Now, I had to figure out a way to actually declare text for the .headertitle depending on what page I was on...
I did this by using a custom template for each page (node) by using this file.. "page--node--nodeid.tpl.php".
So, for my ABOUT US page, I created a tpl.php file called "Page--node--7.tpl.php".. for this page, the 7 is the nodeid which is easy to find.
Then, I added the following PHP code to declare text for the .headertitle specifically on the ABOUT US page which looks like this...
<?php $headertitle = "ABOUT<span class='white'>.US</span>"; include('includes/header.php'); ?>
DONE AND DONE.
I'll do that for each page. :)
To start out: Not Wordpress! Just plain old PHP. Here's what I'm trying to do:
I've got a horizontal navigation bar at the top of my page with the links 'Home, About, Info, Contact'
Most of the pages also have a vertical navigation bar, the sidebar.
If I'm on the Home page, no sidebar needs to be shown.
If I'm on the About page there has to be a sidebar with various other subjects. The Contact page needs to show a sidebar with a Route Description and Contact Form link etc.
I was thinking about achieving this with $GLOBAL variables and put something like $GLOBAL['sidebar] = 'home' $GLOBAL['sidebar'] = 'contact' etc... on top of every page. In the PHP file that would render my sidebar I would use an if structure to see what sidebar needs to be rendered. But using global variables is something I've always been taught is wrong and shouldn't be used. After that, my mind drifted to $SESSION variables, but that would actually be exactly the same but with some extra concerns like session_start() etc.
I'm self-taught in PHP so I don't know what could be best used to solve this particular (and I presume very common) "issue". Any insights about this matter would be greatly appreciated. Thanks.
The solution will depend a lot on how you've set up your code structure already, but in more general terms the way I usually do it is to:
Include the sidebar as part of your template included on every page.
Set up your sidebar along the lines of this:
<?php
if (sizeof($sidebarModules)>0) {
?>
<div id="sidebar">
<?php
if (in_array('contact',$sidebarModules)) {
// display contact form
}
if (in_array('route',$sidebarModules)) {
// display route description
}
if (in_array('login',$sidebarModules)) {
// display login
}
?>
<\div>
<?php
}
?>
Then at the top of each page make sure you define the array $sidebarModules. Something like:
<?php
$sidebarModules = array(
'contact',
'login',
'description'
);
?>
I'm not sure if this is the best solution, but it's worked well for me in the past.
Edit:
or do it more efficiently if you're templates are named in a standard convention, e.g.:
<?php
if (sizeof($sidebarModules)>0) {
?>
<div id="sidebar">
<?php
foreach ($sidebarModules as $module) { // loop round all modules
include($module.'_tpl.php'); // include module template
}
?>
<\div>
<?php
}
?>
this is in my theme.info file of my Drupal theme:
regions[conf_modules] = Configurator: modules
I'm using multiple templates for different node types. In one of them I'd like this region/block to show up. So I've put this in node--configurator.tpl.php:
<?php print render($page['conf_modules']); ?>
In the Drupal administration panel I have assigned a views block to the region, but on the node--configurator.tpl.php pages, the views block is not shown. Am I using render() properly? What's going wrong here? Thanks in advance!
In node templates, $page is simply a status variable that is:
True if the node is being displayed by itself as a page.
However, you can add regions to the page for specific content types through your page.tpl.php if you like. Something like below should work if placed in page.tpl.php:
<?php
if ($node->type == 'CONTENT_TYPE') {
print render($page['conf_modules']);
}
?>
Can anyone advise how I'd alter a template which is called on every page load to display a particular section on just the one page?
I hope I explain this well enough...
index.php includes;
require_once('./cache/templates/sidebar.php');
Every subsequent page is built uses what's defined in this index.php file, meaning the sidebar.php is a must.
I'm wanting to edit sidebar.php to contain an advert which displays solely on the index page.
At the moment, when I edit sidebar.php, so for instance, to display the letter "B", it will display on the homepage, and every other page like so;
Index Page: http://img.photobucket.com/albums/v684/nilsatis/1stack.jpg
Every other page: http://img.photobucket.com/albums/v684/nilsatis/2stack.jpg
How can I dictate one area of an included file to display on one page but exclude showing on others?
Edit: Thanks very much for your time. It's really appreciated.
I inherited/purchased the website and I'm finding the index.php file very temperamental.
I'm attempting to put this code within the sidebar (or below it, above the footer) but any amend on index.php breaks it.
}
if (isset($url[1])) require_once('./cache/html/'.$url[0].'/'.$url[1].'.php');
else require_once('./cache/html/'.$url[0].'.php');
}
}
require_once('./cache/templates/sidebar.php');
}
require_once('./cache/templates/footer.php');
A quick and dirty hack would be inserting a custom CSS stylesheet on the index.php page that makes some div that's part of "sidebar.php" visible.
Example:
sidebar.php:
<?php
echo '<div id="theLetterB" style="display:none">B</div>';
?>
index.php:
<?php
if ($_SERVER['PHP_SELF'] == 'index.php') // Replace this with something to differentiate between pages
{
echo '<style type="text/css"> #theLetterB { display:block; } </style>';
}
?>