The insert page plugin allows you to insert the contents of one page into another.

This short plugin started as a way to simplify a complicated page. Our home wiki has a schedule at the top, my links in the middle and my girlfriend's across the bottom. Each section is a table and between the tables we have some animated gifs. Needless to say, this made the page confusing to edit. With this plugin I can now do something like this:

[{INSERT com.hurlbert.jspwiki.plugin.InsertPagePlugin pageToInsert=HomeSchedule}]
[ValDay/fishswimming.gif][ValDay/ake.gif]
[{INSERT com.hurlbert.jspwiki.plugin.InsertPagePlugin pageToInsert=HisLinks}] \\ \\
[{INSERT com.hurlbert.jspwiki.plugin.InsertPagePlugin pageToInsert=HerLinks}] \\

Enjoy - Scott Hurlbert

Very good. I will rewrite the syntax a bit, but expect to see something like this in the next release.

-- JanneJalkanen

Hey great! As for the syntax, I'm relatively new to java and this is my first public offering to the JSPWiki so I look forward to seeing the changes. I'm still at that stage where I'm learning everyday. Thanks

-- ScottHurlbert

There's now a InsertPagePlugin in 2.1.37. Thanks, Scott (and AlainRavet, who also suggested the same thing). You can see an example of it running at my weblog.

What is the basic syntax ?? -- OlivierVit

[{INSERT InsertPagePlugin pageToInsert=EditUserHelp}] this doesn't work, how can I use it? -- SebastianPetzelberger


I'm having problems with the 2.1.37 plugin and getting it to include some pages. I can't get it to include my Main or About pages or my FosterSchucker page. It seems to have something to do with including a plugin. Has anyone else seen this? -- FosterSchucker

package com.hurlbert.jspwiki.plugin;

import com.ecyrd.jspwiki.*;
import com.ecyrd.jspwiki.plugin.*;

import java.util.*;

/**
 *  Inserts a WikiPage into another WikiPage.
 *  <P>
 *  <B>Parameters </B>
 *  <UL>
 *    <LI>pageToInsert - The page to be inserted.
 *  </UL>
 */

public class InsertPagePlugin implements WikiPlugin
{
	public static final String PARAM_NAME_OF_PAGE_TO_INSERT = "pageToInsert";

	public String execute( WikiContext context, Map params )
	throws PluginException
	{
		WikiEngine engine = context.getEngine();
		//
		//  Parse parameters.
		String nameOfPageToInsert = "";
		
		if( (nameOfPageToInsert = (String)params.get(PARAM_NAME_OF_PAGE_TO_INSERT)) == null )
		    return "no page found";
		//
		// We should now have a page to insert.
		 WikiPage wpage = engine.getPage(nameOfPageToInsert);
		//
		// Lets make sure we got a page
		if( wpage == null )
			return "'" + nameOfPageToInsert + "' page not found";
		else
			return engine.getHTML( context, wpage );
    }
}

I found that if I change the page not found logic to be the code below, I can use the InsertPagePlugin like i use a link to create content on the fly.
if( wpage == null )
                        return nameOfPageToInsert + "<a href=\"Edit.jsp?page=" + nameOfPageToInsert + "\">?</a> page not found";
		else
			return engine.getHTML( context, wpage );


I thought it would be nice to add a style to the included page, so we can choose between include the link in order to build the final page or just becase we want to highlite another included page

So here's the new code


String highlite = String.valueOf(params.get("HighLiteType"));		
if( wpage == null ) {
	return nameOfPageToInsert + "<a href=\"Edit.jsp?page=" + nameOfPageToInsert + "\">?</a> page not found";			
}
else
{			
        return "<div class=\""+highlite+"\">"+engine.getHTML( context, wpage )+"</div>";
}

Call Example

[{INSERT com.hurlbert.jspwiki.plugin.InsertPagePlugin pageToInsert=HomeSchedule HighLiteType=IncludeYellow}]
Of course the name (ie. includeYellow) must be the name of a div class type defined in the css like this

.includeYellow { background: #F9F9EB; margin: 5px 0px 5px 0px; padding: 2px 0px 2px 10px; border: 1px dotted #FF8000; }

This way you can have as many type of inclusion as you want, as long as you add styles to the css

Max Amato 22/12/2004

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-36) was last changed on 26-Sep-2007 23:20 by JanneJalkanen