+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Inserting Variables in Templates

  1. #1
    Join Date
    Jun 2007
    Posts
    7

    Default Inserting Variables in Templates

    Hi.

    I'm trying to insert Environment variables such as UserName and TimeStamp in my templates.

    I'm working on FAQ pages where lots of different user contribute with FAQ-entries and I want Username and Time to be inserted automatically.

    Is this a feature available?

    best regards

    KKS

  2. #2
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    Welcome to the forums KKS!

    Let me see if I understood you correctly. You want to be able to create a template page that when inserted adds the user's name and the timestamp into the final document for this entry, correct?

    Here how you can do it in DekiWiki "Hayes":
    1) create a new template page (e.g. Template:FAQ Entry)
    2) add the layout and text you want to appear for an FAQ entry
    3) then add {{SUBST:username}} and {{SUBST:timestamp}} where you want the user name and the timestamp to appear
    4) save the template

    Now, go into your FAQ section, edit the page, and click 'Templates' in the editor toolbar. Select the 'FAQ Entry' template and click 'Insert Template'.

    This will insert a copy of the FAQ entry. Now, when you save it, the editor will replace {{SUBST:username}} and {{SUBST:timestamp}} with their respective values and save them. Note that the SUBST: prefix makes this happen. Withtout it {{username}} and {{timestamp}} would not get replaced on save and would continue to show the current users name and the current time, which is probably not what you want.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  3. #3
    Join Date
    Jun 2007
    Posts
    7

    Default

    Hi SteveB.

    Thank you for your reply.
    You've understood my intention - what you describe is exactly what I want.

    I've tried to use your suggestion, but it didn't work...

    I Put in the following in my template and saved it:

    {{SUBST:username}} , {{SUBST:timestamp}}

    When generating a new article based on that template it still shows the same after I save:

    {{SUBST:username}} , {{SUBST:timestamp}}

    What I wanted was something like this:

    KKS, 29/06/2007 12:00

    I've been looking in to the calendar template - it works just fine - the code in the curly brackets is replaced by a calendar when saved.

    Is a list of valid SUBST available somewhere? It would be very nice ;-)

  4. #4
    Join Date
    Mar 2007
    Location
    Denmark
    Posts
    269

    Default

    Hi kks

    It's because you are using the Gooseberry++ version of DekiWiki and not the Hayes version.. Hayes is the next version of DekiWiki and are only released in a Beta2 version right now.

  5. #5
    Join Date
    Aug 2007
    Location
    Upper Bucklebury, UK
    Posts
    36

    Default

    Oddly subst doesn't seem to be working in the latest rc2 version, I've set up an exact copy of the example template but the subst values don't seem to work with a paramterised template.

  6. #6
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    Templates don't evalute their contents since they can be parameterized. However, if you insert a template into a document, the SUBST: command will be applied.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  7. #7
    Join Date
    Aug 2007
    Location
    Upper Bucklebury, UK
    Posts
    36

    Default

    hi steve - I've created by templates with username and submitted time according to the documentation, but neither {{SUBST:user.name}} or {{SUBST:date.now}} show the expected values. instead it shows the logged in user
    it appears that while using the FAQ page and a series of FAQ entires, all values will be updated as you're effectively creating new entries for every page edit.

  8. #8
    Join Date
    Jul 2006
    Location
    San Diego, CA
    Posts
    5,450

    Default

    scott, can you provide more details? Was this something that was working before? What does the template look like and how are you using it. Thx.
    Steve G. Bjorg - Chief Architect
    Did you check the MindTouch FAQ?
    Found a bug? Report it.
    Follow me on Twitter
    Find us on IRC: irc.freenode.net #mindtouch

  9. #9
    Join Date
    Aug 2007
    Location
    Upper Bucklebury, UK
    Posts
    36

    Default

    hi steve - here's the template i was using:

    Q. {{ args.question }}

    A.
    {{ args.answer }}





    Submitted by: {{ SUBST:user.name }} on {{ SUBST:date.now }}

    is this correct, or should I be using:
    {{SUBST:username}} , {{SUBST:timestamp}}?
    Will try that out as well

  10. #10
    Join Date
    Aug 2007
    Location
    Upper Bucklebury, UK
    Posts
    36

    Default

    D'OH!

    I'd been using:
    {{ wiki.template( "FAQ Entry", {question: "How do I use the Wiki?", answer: "Visit: http://wiki.opengarden.org/ and look at the user manual (i.e. http://wiki.opengarden.org/Deki_Wiki/User_Manual)"}) }}

    but I should've used:
    {{ SUBST:wiki.template( "FAQ Entry", {question: "How do I use the Wiki?", answer: "Visit: http://wiki.opengarden.org/ and look at the user manual (i.e. http://wiki.opengarden.org/Deki_Wiki/User_Manual)"}) }}

    then it will work properly. sorry - being a bit dense.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts