How to include pages in each other?
ak - September 10, 2006 - 06:57
Hi, I'd like to kombine some pages. I know the method here how to pull a page with the nid in to an other. But I'm trying to include system or module generated pages like the contact form or tagadelic page. So I don't have a nid to refere to. How can I include such generated pages in my own story or views page?

iframe
In a pinch, you could use something like
<?php
$frame = "<iframe src=\"http://www.example.com\" width=\"100%\" height=\"1600\">";
$frame .= "<!-- Alternate content for non-supporting browsers -->";
$frame .= "Your browser won't work here.";
$frame .= "</iframe>";
print $frame;
?>
or
$url = "http://example.com/page.html";print file_get_contents($url);
Yes but ...
auch... I didn't even think of the methods you're suggesting so let me be a little clearer because these methods would show up the entire page including header, footer sidebars ect. This wasn't my intention et all. What I'm trying to accomplish is pulling the content of the contact page in to another ( or even in a block ) but just the content, the form and not the entire page.
The usage would be something like I may want my contact form on to show on the about page so I need to pull the contact form on that page somehow, or I'd like to have a categories page where one can browse by tagadelics tagcloud and by a categories tree, all in one entire page. But here again I must include the tagcloud in the page whre I build the tree view.
Thanks for help and suggestions.
Thanks for your reply.
I haven't used it yet, but
I haven't used it yet, but maybe you are looking for something like the exerpt module which "allows allows you to enter a separate excerpt/summary/teaser for a node, which does not have to be a cut off version of the body." http://drupal.org/project/excerpt
Let me know how it works, I may add it soon.
~~~~~~~~~~~~~~~~
Kris
Current project: www.cribfax.com
Thanks but ...
no it's not what I'm looking for.
Use the function menu_execute_active_handler()
menu_execute_active_handler() is responsible for executing the code associated with the current path. With a little bit of code you can have it do this for the path of your chosing. Small warning, pre 4.7 the callbacks did there own call to theme('page', ...) while in 4.7 they can (are suppose to?) return just the part they generate. The old style still works though but will not work the way you want. The point is many paths will work correctly but you may find some that do not.
To try this out create a node of type page.
Add a title and paste the following code in the body
This is the leading text before the calendar<?php
// We save and restore the real path for the page
$q = $_GET['q'];
// Change event to the path you want, this is the part after q= (or after the base path if you have clean URLs enabled)
$_GET['q'] = 'event';
// Get and print the output for just the content associated with the path
// If you see the complete page within a page it means the path callback is probably calling theme('page', ....)
print menu_execute_active_handler();
// Restore the real path for the page
$_GET['q'] = $q;
?>
And this is the footer
Set the input format to 'PHP code' and submit.
Great, this is it!
Thank you man, I tried it with the contact page as I mentioned and it works great, just the way I want it to. This snipped will give me much more flexibility and control over the display of module generated pages. Big thanks. I'm on 4.7 so I should'nt have any trouble with the callback stuff. I hope nothing is going to change in 5.0. This would be a god one for the handbooks, at least I'm going to use this extensively I think, as this comes in really handy on several different approaches.
Sweeet! But...?
How do I implement this exactly?
When I add this code to my about page and change 'event' to 'contact' my contact form shows up. So sweet!
When I change 'event' to 'node' I get the "welcome to your new Drupal website page" text. That's probably because I'm using frontpage.module and I haven't "published" anything to the frontpage, I presume. (?) (Ah, but this gives me an idea!)
However, when I change 'event' to 'story' or 'blog' or the path to a node, say 'introduction', I just get the number 2. It's obvious to me I'm doing something wrong. Or, I'm just plain clueless. Probably both. Can you explain it to me?
The path needs to be a valid path
The path needs to be a valid path, so for example if your site is at www.example.com the contact form would be at http://www.example.com/index.php?q=contact (or http://www.example.com/contact with clean urls enabled). The part after the 'q=' is what you need to set $_GET['q'] to. 'story' as far as I know is not a valid path nor is 'blog' but 'blog/N', where N is a valid user id, is a valid path (ex: 'blog/1'). In the case of a single node you can use 'node/NID', where NID is a valid node id though it is probably faster to use node_load() and node_view() to view the contents of a single node.
If you want to handle path aliases you would need to change
$_GET['q'] = 'event';to
$_GET['q'] = drupal_get_normal_path('event');replacing 'event' with the path you want.
If you see a '2' it means the path was not found (not valid) and a '3' means access was denied.
Awesome!
This is one of the best code snippets I've come across. This is awesome. Thanks!
Agree this is one of the best... but a question (of course)
I agree this is one of the most important snippets (esp. for Drupal newbies like me :-)
But I did notice a strange side-effect.... my "view, edit, track" tabs at the top of each content page disappears when I use this snippet.
In other words, if I decide to edit a page of content that I already posted previously, and type "Hello World" in the body, then preview the page..... I usually see the "View, Edit, Track" tabs at the top, then the text "Hello World". Life is good.
_But_ if I use this snippet and preview the same page, I no longer have any ability to View/Edit/Track.
I used the snippet in a block and then placed the block in several pages and it handily removed all "View, Edit, Track" tabs from those pages even though I was logged in as admin with full superuser rights.
I tried a few different themes to see if maybe the theme developer missed a nuance. Same result. I'm guessing that I'm the one missing something here... help appreciated.
Emilio
I have noticed the tabs disappear also
I have noticed the tabs disappear also and it is on my list (rather long) of things to do. I am guessing it has to do with the way tabs are produced for the page, but like I said have not tracked it down yet.
Very Powerful - Thanks
Hey!
Just wanted to say thanks for a great solution. I had originally posted a seperate thread and got pointed to this one. It worked perfectly to solve the features I desribed in my post and below.
Michael
www.webemulsion.com
Awesome! But...
Is there a way to use this to print the secondary links of a page? I'd like to create my own administration "page" and using this method works great to say display the settings on my page... but what I'm really interested in are the secondary links which don't display. I'll probably figure it out but I just thought I'd ask in case I run into a wall.
[Edit: Well I figured out an easier way to do what I wanted. I will use the above method, often I'm sure, for other things but the easiest way to add a menu to a page is with the menu_item(pid) function where pid is the menu ID. The id can be found on the menus administration page by hovering the cursor over "edit" for the menu in question. The id will be shown as the last part of the url in your status bar. Hope that helps anyone who didn't know it. ]
$this_menu = menu_item(11);
print $this_menu;
Works great but changes the title
Thanks for the snippet, it works great, but... how can I make sure it does not change the title? I created a page, included the code, the page I want to include is actually "archiv" (an alias for taxonomy/term/130). The title of parent page is X, the title of included page is Y, so I want X to appear as the title, but Y appears instead. Thanks for any help.
This should work
Before the call to menu_set_active_item() add this line
$title = drupal_get_title();and after the call to menu_set_active_item() add this line
drupal_set_title($title);Thanks, it works
Thanks, nevets, it works. (The only details is that your snippet contains
print menu_execute_active_handler();instead ofmenu_set_active_item()you now mentioned.)Another "hear hear!" ...
Another "hear hear!" ... thanks ... exactly what I was looking for.
how about for 5.0
any update on this for 5.0? I use this snippet to numerous pages in 4.7 and I will be very grateful if someone posts an update or an equivalent. :-)
John
indeed!
i could also really use a 5.0 equivilant. this old version seems to almost work, but no matter what node value i enter here:
$_GET['q'] = 'node/1';
i just get 'node' displayed.......
any suggestions?
It it possible to have the PHP Results open in an IFRAME?
I tried to use your PHP code shown below for use with the aggregator RSS feeds. I placed the code in the body of a new page (?q=node/35) and set the input format to PHP.
It works fine but the aggregator uses pagination, ie. 1 2 3 4 5 6 7 8 9…next ›last » at the bottom of the page. When you click on any of these pagination links, the resulting page is the aggregator page itself (?q=aggregator&page=1).
Is there any way to modify the PHP code so that the aggregator results display in a IFRAME so that the pagination works correctly keeping the user on the original page (?q=node/35) ?
Original Code
This is the leading text before the calendar<?php
// We save and restore the real path for the page
$q = $_GET['q'];
// Change event to the path you want, this is the part after q= (or after the base path if you have clean URLs enabled)
$_GET['q'] = 'event';
// Get and print the output for just the content associated with the path
// If you see the complete page within a page it means the path callback is probably calling theme('page', ....)
print menu_execute_active_handler();
// Restore the real path for the page
$_GET['q'] = $q;
?>
And this is the footer
Aggregator Version
<?php$q = $_GET['q'];
$_GET['q'] = 'aggregator';
print menu_execute_active_handler();
$_GET['q'] = $q;
?>
Thanks,
Sam Raheb (Sam308)
Limit number of nodes returned
I like the aggregator example above. How can I limit the number of nodes that are displayed?
Thanks
Search results within a page
I would like to do something similar: to display a search form (no problem there, using the above!), and have the results display within the original page underneath the search box.
Unfortunately the search submit redirects to the search/node (or user) page, and from a look at search_form_submit (http://api.drupal.org/api/4.7/function/search_form_submit) the redirect looks hard-coded.
Can anyone suggest an approach that might get me started? Perhaps an iframe, but restricted to the content only (not the full page). Is such a thing possible?
Thanks!
If there are some module
If there are some module that able to republish (link content) of existent node in new nodes?
1. I want get list of allowed nodes in select menu for republishing.
2. Then choose existent node.
3. And after get new node with existent node's content.