System Variables for your Wiki Page
The current implementation of live templates allows the use of page variables like %%title%%, %%fullname%%, %%category%%, %%created_by%%, and %%created_at%%.
Unfortunately you can use these page variables only within a live template, not on your original page. Have you ever wondered, if there was a way to use these variables directly on your page?
And even more — what about a way to define your own variables that you then can use (multiple times) on your page?
Here may be a solution for you (before implementing this, please have a look at the limitations).
Step by Step
Step 1
Create an a live template called category:_template1 in the category for which you'd like to enable system variables with the following code.
Note: Copy/paste the code exactly as-is, don't remove or change anything
[!--
[[code]]
[[include %%category%%:_endcomment]]
[[include %%fullname%%
title=%%title%% |
linked_title=[/%%fullname%% %%title%%] |
parent=%%parent_title%% |
parent_linked=[http://%%site_name%%.wikidot.com/%%parent_fullname%% %%parent_title%%] |
fullname=%%fullname%% |
name=%%name%% |
category=%%category%% |
link=%%link%% |
tags=%%tags%% |
_tags=%%_tags%% |
created_by=%%created_by%% |
rating=%%rating%% |
comments=%%comments%% |
revisions=%%revisions%% |
children=%%children%% |
size=%%size%% |
updated_by=%%updated_by%% |
created_at=%%created_at|%e %b %Y, %H:%M %Z%% |
created_at_start=%%created_at|[!--%%--] |
created_at_end="]] |
updated_at=%%updated_at|%e %b %Y, %H:%M %Z%% |
updated_at_end="]] |
updated_at_start=%%updated_at|[!--%%--] |
%%content{2}%%
]]
[[include %%category%%:_startcomment]]
[[/code]]
--]
[[include %%category%%:_startcomment]]
%%content{1}%%
[[include %%category%%:_endcomment]]
Step 2
Create a page called category:_startcomment in the same category as in Step 1 with the following code.
[!--
[[code]]
Step 3
Create a page called category:_endcomment in the same category as in Step 1 with the following code.
[[/code]]
--]
How does it work
The general idea here is, not to leave page content rendering to the live template (which is what “standard” live templates do by specifying the %%content%% variable), but instead directly include the page content and at the same time supply all page variables as include variables.
See System Variables: Details for a detailed technical discussion of the ideas and concepts used.
Limitations
When using page variables through live templates, be aware of the following limitations:
- Previewing while editing a page will show artifacts: the text “[[include %%category%%:_startcomment]]” at the very top of the page, and “[[include %%category%%:_endcomment]]” at the very bottom of the page
- Some rare page contents, e. g. unbalanced [[code]] or [[/code]] tags without their corresponding counterpart, will break the live template
- If you'd like to enable system variables for the default category, you'd have to
Examples
System Variables
Instead of using live template page variable … | Use include variable … | Example |
%%title%% | {$title} | System Variables |
%%linked_title%% | {$linked_title} | System Variables |
%%parent_title%% | {$parent} | Page Content |
%%parent_title_linked%% | {$parent_linked} | Page Content |
%%children%% | {$children} | 0 |
%%fullname%% | {$fullname} | erichsteinboeck:system-variables |
%%name%% | {$name} | system-variables |
%%category%% | {$category} | erichsteinboeck |
%%link%% | {$link} | http://community.wikidot.com/erichsteinboeck:system-variables |
%%created_by%% | {$created_by} | ErichSteinboeck |
%%updated_by%% | {$updated_by} | James Kanjo |
%%rating%% | {$rating} | 9 |
%%comments%% | {$comments} | 2 |
%%revisions%% | {$revisions} | 18 |
%%size%% | {$size} | 8428 |
%%tags%% | {$tags} | include live system template variables |
%%_tags%% | {$_tags} | _content-advanced _l4 _redirect |
%%created_at%% | {$created_at} | 21 Mar 2009 12:42 |
%%created_at| format| agohover%% | {$created_at_start} format| agohover{$created_at_end} e. g. {$created_at_start} %c| agohover {$created_at_end} |
21 Mar 2009 12:42 |
%%updated_at%% | {$updated_at} | 09 May 2010 06:03 |
%%updated_at| format| agohover%% | {$updated_at_start} format| agohover {$updated_at_end} e. g. {$updated_at_start} %c| agohover {$updated_at_end} |
09 May 2010 06:03 |
User Variables
What you type … | What you get … |
+++++ {$users} Users! |
300 000 Users!We have just reached 300 000 registered users at Wikidot. Nice! |
Global Variables
This is pretty simple but may not be obvious. To be able to use variables in any page in the category, add them next to the System Variables. Right before the "%%content{2}%%", you may define other variables besides system ones (e.g. you can put "users=300 000 |"). NOTE: You need to add a pipe "|" at the end of each global variable you define.
Links
- Community wishlist System variables
- Comunity How-To System Variables: Details
Backlinks
Author
ErichSteinboeck. Please visit his/her userPage.