Feature #2854

macro to make wiki template

Added by Vianney Lecroart over 8 years ago. Updated about 4 years ago.

Status:ClosedStart date:2009-02-27
Priority:NormalDue date:
Assignee:-% Done:


Category:Plugin API
Target version:-


I created a basic system to enable wiki template page, like in MediaWiki.

Just add the attached file in the macros.rb


  • Create a template wiki page, for example TemplateTest and write:
    My name is t_name and I'm t_nat.
  • Create an instance wiki page, for example Test1 and write:
    {{template(TemplateTest, t_name=acemtp, t_nat=French)}}

    and it'll display:
    My name is acemtp and I'm French.

wiki_template.txt Magnifier (860 Bytes) Vianney Lecroart, 2009-02-27 09:53


#1 Updated by Craig Taverner over 8 years ago

I wanted to use this immediately, so I wrapped it in a redmine plugin. There was a small trick needed, so here's the relevant code to be put, for example, in redmine_wt/lib/wt.rb and called from redmine_wt/init.rb using require_dependency.

# Dependency loading hell. http://www.ruby-forum.com/topic/166578#new
require 'dispatcher'
Dispatcher.to_prepare do
  Redmine::WikiFormatting::Macros.class_eval do

    # wiki template macro
    desc "Replace token inside a template. Example:\n\n !{{template(WikiTemplatePage,token=foo,token2=bar)}}." 
    macro :template do |obj, args|
      page = Wiki.find_page(args.shift.to_s, :project => @project)
      raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)

      @included_wiki_pages ||= []
      raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
      @included_wiki_pages << page.title
      out = textilizable(page.content, :text, :attachments => page.attachments)

      args.collect do |v|
        key = $1
        value = $2.strip.gsub("<br />", "")
        out = out.gsub(key, value)

I've not published this plugin, since it's so simple, but thought I should at least comment on this issue. Basically the above code is 90% Vianney's wiki_template.txt file, with a small wrapper based on code I saw in the init.rb of the task-board plugin by Dan Hodos.

#2 Updated by Vianney Lecroart over 8 years ago

Thanks for the plugin, I didn't know that we can add new macro with plugin (it's my first redmine and ruby hack), it's nice.

#3 Updated by Javier Barroso about 8 years ago

Hi Craig,

Could you explain a bit more how install your little plugin ? In my redmine init.rb is only in plugins.

So, which should be the content of init.rb.

How could I add this plugin to plugins directory ?

vendor/plugins/redmine_wikitemplate/{init.rb, wt.rb}, any file more ?

Thank you !

#4 Updated by Neil McFarlane over 6 years ago

This seems quite useful, any chance we could get something like this integrated? Perhaps "custom parameterizable macros"?

#5 Updated by William Roush almost 6 years ago

Wiki templates are a huge deal, we should have some official support for them.

#6 Updated by Jan Niggemann (redmine.org team member) almost 5 years ago

Closing this, status is resolved since 400 days and more (issue was last updated more than 400 days ago)...

#7 Updated by Jan Niggemann (redmine.org team member) almost 5 years ago

  • Status changed from Resolved to Closed

#8 Updated by Holger Just about 4 years ago

As one of our customers at Planio Redmine hosting asked for this macro, we adapted it by reducing code duplication and transformed it into a full plugin. You can find the GPL-licensed plugin at https://github.com/planio-gmbh/redmine_wiki_template.

Also available in: Atom PDF