Skip to content

Commit

Permalink
Apply custom replacements also to regular page/namespace templates
Browse files Browse the repository at this point in the history
This makes it possible to e.g. use @title@ in a regular page or
namespace template if the page is created via the "new page" form.
  • Loading branch information
michitux committed Sep 3, 2018
1 parent fb270d7 commit c854e21
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ function _handle_newEntry(Doku_Event $event) {

$TEXT = pageTemplate($ID);
if (!$TEXT) {
$data = array('id' => $ID, 'ns' => $ns, 'title' => $_REQUEST['title']);
$TEXT = $this->_pageTemplate($data);
// if there is no page template, load our custom one
$TEXT = io_readFile(DOKU_PLUGIN.'blog/_template.txt');
}

$data = array('id' => $ID, 'ns' => $ns, 'title' => $_REQUEST['title']);
// Apply replacements regardless if they have already been applied by DokuWiki in order to
// make custom replacements like @TITLE@ available in standard page templates.
$TEXT = $this->_pageTemplate($TEXT, $data);

return 'preview';
} else {
return 'edit';
Expand All @@ -118,12 +124,11 @@ function _handle_newEntry(Doku_Event $event) {
/**
* Adapted version of pageTemplate() function
*/
function _pageTemplate($data) {
function _pageTemplate($text, $data) {
global $conf, $INFO;

$id = $data['id'];
$user = $_SERVER['REMOTE_USER'];
$tpl = io_readFile(DOKU_PLUGIN.'blog/_template.txt');

// standard replacements
$replace = array(
Expand Down Expand Up @@ -164,8 +169,7 @@ function _pageTemplate($data) {
}

// do the replace
$tpl = str_replace(array_keys($replace), array_values($replace), $tpl);
return $tpl;
return str_replace(array_keys($replace), array_values($replace), $text);
}

/**
Expand Down

0 comments on commit c854e21

Please sign in to comment.