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

drawk - September 10, 2006 - 07:18

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 ...

ak - September 10, 2006 - 13:57

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

kweisblatt - September 10, 2006 - 14:21

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 ...

ak - September 10, 2006 - 15:13

no it's not what I'm looking for.

Use the function menu_execute_active_handler()

nevets - September 10, 2006 - 14:44

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!

ak - September 10, 2006 - 15:27

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...?

jordan.page - September 10, 2006 - 16:30

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

nevets - September 10, 2006 - 17:19

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!

jordan.page - September 10, 2006 - 19:18

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)

ebernabei - October 30, 2006 - 04:54

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

nevets - October 30, 2006 - 05:16

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

MikeyLikesIt - October 11, 2006 - 14:06

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.

I'm building my first 4.7 site and am loving all the improvements over 4.6. Drupal and everyone in the community rocks! but enough ass kissin ...

I am making use of the book feature extensively for static type of content on the site, particularly for describing the organizations programs, about us pages and pages asking for support from the community.
Taxonomy Lists inside books

The book feature allow me to specify any node type page as "living" inside the structure of the book, which is great, but I want to be able to specify that certain taxonomy pages live within the book. ie. give me a node teaser list showing all the nodes that match certain criteria. Actually, I just realized, that I could probably use the Views module to create these pages and then attach them to the books structure. If you have other suggestions for how to achieve this, please let me know.
System Pages

I use the feedback module to create a "Contact Us" page. It serves my needs well, but I can't figure out how to get the resulting page to live within the structure of my book. I like for the Contact Us page to reside within the About Us section of the site. Does anyone have any idea how I can acheive this?

If you want to see the work in progress, you can see the test site at cabwhp.webemulsion.com/about_us. If you click on Contact Us, it will forward you to the contact us page I created using feedback, but notice that the book navigation on the side disappears, because the pages doesn't live inside the book.

Michael
www.webemulsion.com

Awesome! But...

rwfaught - October 20, 2006 - 05:34

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

intu.cz - November 2, 2006 - 21:04

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

nevets - November 2, 2006 - 22:33

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

intu.cz - November 2, 2006 - 23:34

Thanks, nevets, it works. (The only details is that your snippet contains print menu_execute_active_handler(); instead of menu_set_active_item() you now mentioned.)

Another "hear hear!" ...

jahf - December 6, 2006 - 06:56

Another "hear hear!" ... thanks ... exactly what I was looking for.

how about for 5.0

JohnNoc-old - December 6, 2006 - 07:56

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!

vegeneric - January 10, 2007 - 21:43

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?

Sam308 - January 26, 2007 - 09:33

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

jarea - April 12, 2007 - 04:46

I like the aggregator example above. How can I limit the number of nodes that are displayed?

Thanks

Search results within a page

dbassendine - July 14, 2007 - 18:34

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

Lunya - January 16, 2007 - 14:04

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.

 
 

Drupal is a registered trademark of Dries Buytaert.