Quote from: eko40 at Aug 26, 2005, 05:22 AM
If only I could understand... what to exactly do to have this mod work with a print this page button...
You should use the css way as Susan describes. It’s the better option.
Just to explain how the plugin works here’s how you could also do it:
- First duplicate your main template and change it so that it prints nicely
- You could also create a new template only having [*content*]
- Name your new template ’printpagetemplate’
- Create the snippet and plugin as shown below
- Use [[printpagelink]] in your content where you want the link
And optional:
- Customize the snippet to your needs, use an image, add a target to open the link in
- Add javascript to your printtemplate to open the print dialog automatically
- Separate the content from the snippet by using Olaf’s tip
http://modxcms.com/forums/index.php/topic,718.msg4149.html#msg4149
Create a snippet printpagelink:
// Set the name of the template used for printing
$printtemplate="printpagetemplate";
$id = $modx->documentIdentifier; // Get current document
$link ="<a href=\"[~$id~]?template=$printtemplate\">print this page</a>";
return $link;
Since I used selecting the template by name, use this modified plugin:
/*
* Written by: Theo Ketsinga
* Created: 8/2005
* For: MODx cms (modxcms.com)
* Name: ChangeTemplate
* Description: Enables template modification at runtime by parameter
* (selection by name)
* Events: OnLoadWebDocument
* Version: 1.1
*
* Put this text into a new plugin and set the System Event
* 'OnLoadWebDocument'. You can now override the template for a
* page by adding the parameter &template=<template_name> to a page.
*
*/
if (isset($_REQUEST['template'])) {
$overrideTemplate=$_REQUEST['template'];
$sql = "SELECT * FROM ".$this->getFullTableName("site_templates")." WHERE ".$modx->getFullTableName("site_templates").".templatename = '".$overrideTemplate."';";
$result = $modx->dbQuery($sql);
$rowCount = $this->recordCount($result);
if($rowCount>1) {
$this->messageQuit("Incorrect number of templates returned from database", $sql);
} elseif($rowCount==1) {
$row = $this->fetchRow($result);
$modx->documentContent = $row['content'];
$modx->documentObject['template']=$row['id'];
}
}