Drupal arguments in a menu - drupal

By default on a page I have the following menu:
Profile /profile
Albums /album
Awards /awards
Going to any of those pages will load the page default.
If I go to a page on my site such as /mycontent/1 I wish to change a the menu to be the following.
Profile /profile/1
Albums /album/1
Awards /awards/1
I want to pass the argument (nid) to the menu. Is this possible?
Update
The selected answer does do what I asked. I however have changed how I am doing things to use Panels to display the content. I am then using some CSS and JavaScript to hide and show content. With views caching it seems to be working well.

Yes,use arg(0),arg(1), or arg(2) depending on which variable you want to use. It will use the path like the indexes of an array (0/1/2/3/4/etc...). Drupal will send you these variables as they were before the path was aliased if that is something that has been applied to it. Why are you passing the variable? There is probably a better way to do it the "Drupal" way..

Actually I am working on this same problem currently where I need to translate an aliased path: dept/profile/1 to load node/1223/profile/1 where 1 is the ID of the profile to show.
What I am using now is the URL Alter module and implementing the hook it gives to enable this feature. If you are interested in this maybe we can see if it is possible to get module out with a GUI.
My thread on this that is active now: Using module: url_alter and it's hook: hook_url_outbound_alter()
I am using a node that houses a panel which has a view inside it, for reasons that are site specific.

Related

Drupal page content

I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.

Prepopulate Content Type Args when going to /admin/content in Drupal 7

I created a Drupal site. The admins who will be using the site for content management have no Drupal knowledge and I have been tasked with making this as easy as possible for them. I'm creating an admin control panel and I want a quick link that takes them to the admin content page, but with the "content type" prefilled. For example, for content I have pages, events, resources, and testimonials. I want to provide them with a quick link for editing content type EVENTS only. So it would go directly to admin/content with the type filter set to "events". The URL does not currently add args or anything like that.
Anyone know of a way to do this?
yes you can do this- just use this module: Drupal admin views which supports a REGULAR VIEW for admin/content. The View is set to use ajax though- just remove this option and save it and call /admin/content then. There you will see the resulting filters in the URL (you can even set their keys to a value you like inside the view). Set back to use ajax (if you like) and use the keys in the URL for type it's simple just call /admin/content?type=YOURTYPE

alter content administration page (admin/content)

I'm working on some drupal installation and googled the whole day, but I can't figure out an answer to the following question:
How is it possible to alter the admin/content page in a way that specific roles are only able to see or filter out limited content types?
Please notice that I don't want to restrict node access in general, I just want to make this page less confusing for editors with different roles and tasks.
I know there is the administration views module and there I can set filter fields in the way I want. The problem with this is that I'm not able to enter the views access restrictions and so all I can do is limit the view's content types for all roles.
Can somebody give me a hint how to solve this?
Thank you very much and sorry for bad english.
One way would be to make a custom module.
In this module you would create a page with hook_menu().
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7
Then in the page callback function that you create you load global $user and switch between the $user->roles, out putting different HTML lists of links depending on their role. If you want something a little more dynamic you can always load the various content types with node_type_get_types().
Then go into structure -> menus -> navigation and disable the default link, replacing it with the new page you created.
If you aren't 100% clear on how to do a couple of these things comment here and I will update my answer.

Drupal 7 vocabulary page

I've created a custom page for a specific vocabulary (using zen theme)
page--vocabulary--2.tpl.php
Works so far as I can customise the page, but I cannot for the life of me work out how to render a custom field (field_banner). Very new to drupal, I can find the field at
$page['content']['term']['#term']->field_banner
Basically, on a per 'term' basis, I want to display an array of images (field_banner) at the header of the template. Hope my question makes sense, still overwhelmed by the Drupal way of thinking, so rather confused!
Firstly you need to make sure the field gets loaded on that page. Is it a node ?
What I suggest is you install the dev module and when you see your page you should see dev tab. In that tab you need to find your field set to access. Once you find it in the list then you can access it in your template file.
The code should look something like this
$node->field_link['und'][0]['value']

Drupal 7- How to make a custom module for only front page?

so..I created page--front.tpl.php in my theme directory and it works fine.
now, how do I make a variable that can be used in the page--front.tpl.php?
I can write my php codes inside page--front.tpl.php, but I think there is a better way.
added:
on the front page, I am going to query video and news nodes ONLY. That is why I want to make a new module for only front page.
any suggestions?
I'm not sure what you are trying to achieve here, but OK. You have two options: one is what you're doing now. Write your custom PHP in page--front.tpl.php and you'll be fine. The other is ditching the file and working only with page.tpl.php.
The variable $is_front tells you whether you're on the front page. You can write custom PHP in a conditional block: if ($is_front) { ... }.
Also, you can create a custom block (a view, perhaps, depending on your needs) and set its display restrictions to "only on the listed pages" - and list there. You'll have a custom view loaded only on the front page.
All you need to do have a custom front page is configure your front page in the site information settins (admin/settings/site-information in D6).
Creating a module to display that content is then a completely different thing.
What I would really suggest is looking at Views if you don't know it already. That allows you to build lists of things (nodes, users, ...) and expose them as pages, blocks, rss feeds and much more. You can create a list of nodes with types video and news, expose that as a page and then just point your front page to the path of your view.
you might try using the views module to create your list of videos and nodes. You can set a views page to be your homepage in the site settings.

Resources