I have 3 nodes in my sites.
node/1 - Login
node/2 - Contact
node/3 - Register
I want to have different template for different nodes. If I do as page-node-1.tpl.php , page-node-2-tpl.php , its for the entire page, I don't want that, I want specifically override for node content.
I have already tried the following links:-
Custom template for specific node in Drupal 6?
Using different templates for different nodes in Drupal 7
I am using Drupal 6
I have not used Drupal 6 in a while, but from what I realized, Drupal 6's default node templates will not have a node ID based template suggestion.
That does not mean you cannot do it from a custom theme.
<?php
function THEMENAME_preprocess_node(&$vars) {
$vars['template_files'][] = 'node-' . $vars['nid'];
}
?>
In your theme's template.php, add the above code, replacing the theme name (or merge the function contents if you already have that function). This will make the Drupal check for node-123.tpl.php file (123 being an example node ID), and will use it for in place of node.tpl.php.
Since you mentioned you'd be using node/1 or any node contents to embed a login form, let me tell you that this isn't exactly a good idea. The login form needs to be accessible when the site is in maintenance mode, and it can be hard to manage them later with different deployment environments. This part is completely irrelevant to the question though.
Related
I'm new to Drupal and Drupal 8 and I want to add areas(blocks?) that I can easily add to a page that pulls in and has access to selected view data and fields. What's the easiest way to get this done? It seems like it should be something that's easy to do but Drupal seems to make this really hard to achieve.
I've tried making custom blocks and types via the CMS but then it'd mean editing the content in 2 different places when we need to update areas or add new areas.
I've also tried building a block via a module but I cant seem to pass the information from a view into my template that way.
The blocks will potentially need to be added to more than one page if that' possible too.
What am I missing, why is this so difficult?
Thanks
Although the question is not so specific I would recommend to start from here Understanding Drupal > Overview > The Drupal flow and then move to Drupal Glossary (it is almost the same for 8.x).
This way it will be more easy to understand Drupal parts such as Theme, Region, Block, Template (using Twig for 8.x) etc.
Use the views module to create the block, then use the block layout page admin/structure/block to place the block in an appropriate region. Edit the block and configure the block and set its visibility settings.
I am building in Joomla! version 3.3.6 for my first time. I have built a ton of custom Wordpress in the past. The first challenge I have encoutnered, is the requirement of building a page which does not look anything like the template pages. The client desires a landing splash page, with large images and a gradient background. However, they are using a template already. Now, I know that I shouldn't start my research on Stack Overflow, so I've watched hours of tutorials for beginners on Lynda.com. No one seems to be covering this topic. Any help would be really appreciated.
To explain this idea, I will compare to what I would do in Wordpress. I would create a file named "page-splash.php" and give it a template name: Splash. Then I would fill this page with my choice code. Finally I would create a "Page" object in wp backend and give it the "template" of "splash".
This is very possible and often accomplished in Joomla.
You would simply need a second template installed and assigned to the page. In Joomla, you could technically have a different template installed for every single page if you wanted to. But in this case, you just need a 2nd template.
Start by building a bare bones template, as found here: https://docs.joomla.org/Creating_a_basic_Joomla!_template (or copy the current template from /templates/ directory and update the templateDetails.xml file so it will install as a second template)
Install 2nd template via Extension Manager
Next, make sure your new page is linked within the Menu Manager (as you will need a menu assignment to call the new template in next step)
Go to Template Manager and you can assign your new template to the menu item defined in the previous step.
You now have 2 independent templates running on the same installation and they can be styled and configured independent of one another.
Assigning more than one template is such a common task in Joomla that you can find more details about this in the official documentation: https://docs.joomla.org/J3.x:Switching_templates
Joomla is by Default not a Blog/Template layout cms, but rather a web application builder.
You can get extensions to create custom templates that make Joomla function like a blog application such as ZOO or K2. I would not go the route of creating individual templates for each page as it would be similar to installing a different theme for each page on a WordPress site.
I come from a Wordpress background and i'm trying to wrap my head around content-types and templates.
My issue is that if I have 2 pages which are slightly different in layout, let's call one 'Wide' and one 'Narrow' then I need a content type for both. But if I change my mind and want 'Narrow' to be 'Wide' as well then I need to delete the page and re-add it as the other content type.. which seems very long winded.
In wordpress you build you templates and then assign each page to a template, and if you don't then it defaults to the default template (which in drupal would just be page.tpl.php) I'm just wondering whether there is anything similar in Drupal?
Thanks for any help
Dan
You can do this using a module called Display Suite https://drupal.org/project/ds
If used in conjunction with other modules such as Context or Panels you can create multiple templates and then assign them by Node type, URL etc
Let's say I'm making a blog in Drupal 7, and I want my end user to see a link: "Add Post", and when he clicks on that link he can add a new content. But instead of the default administration page, is it possible to create a new one, which has just the post title, tags, message and etc?
I've been searching for 2 days now, founding nothing about where to start/how to start a specific administration page instead of the default one.
You will have to create a specific module for that which will:
define the blog post editing form you want to have
define a page through a hook_menu function that includes the form
define a menu entry for it in the administrative menu
etc.
You should really get a little more into extending drupal by reading some pro drupal 7 book.
At least start reading http://drupal.org/node/1074360
Another very good starting point is the drupal "examples" module, which provides example code for most things your modules need to do:
http://drupal.org/project/examples
You could probably do all you need to by adding a template for the blog posting page to your theme. This lets you customise the display of the form, without needing to get too deep into Drupal programming.
Alternatively, you could create a module to replace the default blog submission form with one if your own design.
The theming and module design guides on the Drupal website give lits if detail on both these approaches.
James
you can have a different theme for management section, you can have multiple permissions depending on role, you can customize any page using ***node.tpl
Every add/content_type is a form. Forms can be altered with hook_form_alter or hook_form_id_alter.
If you want to have different fields that are shown for different roles, first see if it could be done on the admin/people/permissions page, if not write extra if conditions inside the form_alter.
e.g. check user role:
global $user;
// Check to see if $user doesn't have the administrator role.
if (!in_array('administrator', array_values($user->roles))) {
// Alter the form
}
You can check the form variables with dpm($form) when the Devel modules is enabled.
I'm new to Drupal dev, and was trying to add an existing region variable to my module's preprocessor function.
Basically, I've created a new region for my site (here's the definition from within side my theme's .info file):
regions[feeds] = Feeds
From Administer->Blocks, I've added the blocks I want to the new "Feeds" region.
Then, from another module, the "Advanced Front Page" module, I'm trying to add some PHP to my "front page" inside this module. The Advanced Front Page module just allows the site to have a landing page, instead of immediately viewing a list of other site content, etc. I've enabled PHP for the content area, and then added the following:
<div>
<?php print $feeds; ?>
</div>
It does not print the "Feeds" region, and I believe it's because that region variable is not accessible from outside of the page.tpl.php file. So after looking around, I came upon these links:
http://drupal.org/node/223430
http://drupal.org/node/237391
From there, I tried to add a preprocessor function for the module "Advanced Front Page", which has a module name of "front_page" (or possibly just "front", I'm not 100% sure). Here's my preprocessor function, that I tried to add to both my template.php file, and the /modules/front/front_page.module file (not at the same time, mind you):
function front_preprocess(&$vars)
{
$vars['feeds'] = theme('blocks', 'feeds');
}
Regardless of where I've placed this file (template.php or front_page.module) it doesn't seem to do anything. Any idea where I might be going wrong?
There are several points to address in your question:
I'd second googletorps answer in that you should approach this in a different way.
The *_preprocess functions can only be used to manipulate/inject variables for templates or theme functions, e.g. page.tpl.php, node.tpl.php, theme_links(), etc. As the front_page module does not use a theme function or (special) template to render its output, you can not make the $feed variable there by means of a *_preprocess function.
Sidenote: With *_preprocess functions, naming is crucial. You need to prefix the function name either with the exact module name or the theme name, depending on where you declare it. So in your example, if you want to add a preprocess function to the module, you'd prefix it with 'front_page_', if you add it to your themes template.php, you'd add 'yourThemeName_'.
You could achieve what you want by creating the blocks directly from code in your frontpage content area. Instead of trying to output the (not available) $feed variable, you could call:
theme('blocks', 'feeds')
This will cause Drupal to return the themed blocks for the given region ('feeds' in this case). Note that this is still not a good way to do it, as even if you don't use the region in your page.tpl.php, it still gets created for every page request made to your site!
So I would go with googletorps suggestion, adding the new region only if there are other uses for it also. If I'd just wanted to add some blocks to the frontpage, I would not create a new region, but configure the blocks to show in the content region and simply restrict them to show only for <front> in their visibility settings.
I haven't tried the advanced front page module, but when dealing with regions, you shouldn't do what you have done. It's a bit hacky and actually not needed. I don't know how the module hook into the templating system, but your problem is probably getting region variables into it's scope. But instead of trying to get the region into the frontpage using the module, you should instead get it into your page.tpl.php. You can actually do what you first tried, but I would suggest that you alter it a bit like this:
<?php if ($feeds): ?>
<div id="feeds">
<?php print $feeds; ?>
</div>
<?php endif; ?>
I have improved in two ways.
By adding the if statement, you don't add empty markup. So you wont get an empty div if $feeds doesn't contain anything.
Adding id's to regions is a good idea. It makes styling them or their content a lot easier, also it adds semantic to your page which html is all about.
Now if you only want your blocks to be shown in the front page you can set that up in each of the blocks settings. So you could possibly just use a region that already exist, unless you want your blocks display a outside an existing region. When adding regions it's not a good practice to only add a region to a single page, instead it's much better to control when it's content should be shown. It might be that you don't need to create a new region, but simply can use one that's already made. Also if you want to make some template changes to your front page, you can also create the front-page.tpl.php where you can create a different template layout for your front page if you so desire.