Not logged in. · Lost password · Register
Forum: General Help and Support Templates and Layout RSS
Vector template: new tab like the discussion tab but in different namespace
Page:  1  2  next 
Avatar
retemirabile #1
Member since Sep 2011 · 63 posts
Group memberships: Members
Show profile · Link to this post
Subject: Vector template: new tab like the discussion tab but in different namespace
I'd like to add a new tab to every page that opens a new page in the following pattern:

For the page:

http://herr-kalt.de/englisch/conditional-sentences-tandem

the new tab should open a page like this:

http://herr-kalt.de/hinweise/englisch/conditional-sentences-tandem

So basically, like the discussion tab but with "hinweise" instead of "talk".

I have been able to add this to the TLD, but I can't get it to append the namespace and pagename.

This is what I have added to tabs.php in the user folder of Vector:

//internal wiki link
$_vector_tabs_left["tab-wiki-hinweise"]["text"]      = "Hinweise";
$_vector_tabs_left["tab-wiki-hinweise"]["wiki"]      = ":hinweise:";
$_vector_tabs_left["tab-wiki-hinweise"]["accesskey"] = "H"; //accesskey is optional

Thanks for any help.

Andreas
Avatar
Andreas (Moderator) #2
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
getID() is what you are searching for:
  1. //internal wiki link
  2. $_vector_tabs_left["tab-wiki-hinweise"]["text"]      = "Hinweise";
  3. $_vector_tabs_left["tab-wiki-hinweise"]["wiki"]      = ":hinweise:".getID();
  4. $_vector_tabs_left["tab-wiki-hinweise"]["accesskey"] = "H"; //accesskey is optional

The problem is that you will get a "hinweise" page for every "hinweise" page itself... some kind of recursive. :-p. Therefore you might try the following:


//"Hinweise" tab
$_vector_tabs_left["tab-wiki-hinweise"]["text"]      = "Hinweise";
$_vector_tabs_left["tab-wiki-hinweise"]["accesskey"] = "H"; //accesskey is optional
$namespace_hinweise = ':hinweise:';
if (preg_match("/^".$namespace_hinweise."?$|^".$namespace_hinweise.".*?$/i", ":".getNS(getID()))){
  $_vector_tabs_left["tab-wiki-hinweise"]["wiki"] = ":".substr(getID(), strlen($namespace_hinweise)-1);
  $_vector_tabs_left["tab-wiki-hinweise"]["class"] = "selected";
} else {
  $_vector_tabs_left["tab-wiki-hinweise"]["wiki"]  = $namespace_hinweise.getID();
}

The $_vector_tabs_left["tab-wiki-hinweise"]["class"] = "selected"; is a small improvement for your usecase to highlight both the article and the "Hinweise" tab at the same time to show the context.

The code is not tested (I'm in a hurry) but should work - if you get an error or something like that just write again and I will have a look at it tomorrow.


Edit: sorry, made a logical and syntactical mistake in the code. Should work now... and the link should change if you are on a "Hinweise" Page. So you can switch between article and Hinweise by simply clicking on the link again
I'm so electronic I shit bits
This post was edited on 2012-03-05, 17:59 by Andreas.
Avatar
retemirabile #3
Member since Sep 2011 · 63 posts
Group memberships: Members
Show profile · Link to this post
Thanks for your quick answer. You can see the solution in action here: http://herr-kalt.de/englisch/conditional-sentences-tandem

There remains one problem: when I'm on the "Hinweise" page, the tab for reading the main article also points to "Hinweise" and is highlighted. So there's no way of getting back to the article except by hitting the back button in the browser.

I think the highlighting should be traditional: when Hinweise is displayed, highlight this tab and don't highlight any others and vice versa.

Nonetheless: many thanks for your help.
Avatar
Andreas (Moderator) #4
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
You can get back to the page by hitting "Hinweise" again... However: I have to think about a way to tell the common "Article" tab what to do... not as easy as it seems. I implemented a "discussion" context to make this work for the discussion namespace...
I'm so electronic I shit bits
Avatar
retemirabile #5
Member since Sep 2011 · 63 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the update.

It seemed simple – just another tab that behaves like the discussion tab. But of course, I don't really know PHP and I'm new to Dokuwiki and things are rarely as simple as they seem to a newbie.

If you have an idea of how to solve this, I'd appreciate it very much.

Thanks.
Avatar
Andreas (Moderator) #6
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
I will get a fresh coffee and think about it now :-p Stay tuned...
I'm so electronic I shit bits
Avatar
retemirabile #7
Member since Sep 2011 · 63 posts
Group memberships: Members
Show profile · Link to this post
Thanks. Ich bin gespannt ;-)
Avatar
Andreas (Moderator) #8
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
So, I think the following should do the trick. Insert the following code in vector/user/tabs.php:

//"Hinweise" tab
$namespace_notes = ':hinweise:';
$_vector_tabs_left["tab-wiki-notes"]["text"]      = "Hinweise";
$_vector_tabs_left["tab-wiki-notes"]["accesskey"] = "H"; //accesskey is optional
if (!preg_match("/^".$namespace_notes."?$|^".$namespace_notes.".*?$/i", ":".getNS(getID()))){
  //The current page is a normal wiki page outside the notes namespace. Create a
  //link to the corresponding notes page. Example:
  //  - current page: "foobar"
  //  - link we are creating here: $namespace_notes."foobar"
  $_vector_tabs_left["tab-wiki-notes"]["wiki"]  = $namespace_notes.getID();
} else {
  //If the notes tab itself is the current page, link to the corresponding
  //normal wiki page instead. Example:
  //  - current page: $namespace_notes."foobar"
  //  - link we are creating here: "foobar" (to prevent a recursive notes tab.
  //    Would be $namespace_notes.$namespace_notes."foobar" without this
  //    correction)
  $_vector_tabs_left["tab-wiki-notes"]["wiki"] = ":".substr(getID(), strlen($namespace_notes)-1);
  $_vector_tabs_left["tab-wiki-notes"]["class"] = "selected";

  //Overwrite the behavior of the article tab. Normally, it would link to the
  //current "Hinweise"-page. We want to link the corresponding normal wiki page
  //instead to make it easy for the user to get back to the corresponding normal
  //wiki page
   $_vector_tabs_left["ca-nstab-main"]["wiki"]  = ":".substr(getID(), strlen($namespace_notes)-1);
}

Please give me feedback if it works and if it fits your needs now...

Edit:
Quote by retemirabile:
It seemed simple – just another tab that behaves like the discussion tab. But of course, I don't really know PHP and I'm new to Dokuwiki and things are rarely as simple as they seem to a newbie.

Adding new tabs is simple (in principle - at least I tried to make it simple). However, the "Hinweise"-tab itself needs some intelligence because it has to know how to behave on different pages. And this makes it a bit more difficult. ;-)


Edit2:
just strip the $_vector_tabs_left["tab-wiki-notes"]["class"] = "selected";  If you don't like the highlightning of both the article and hinweis-tab
I'm so electronic I shit bits
This post was edited 2 times, last on 2012-03-07, 10:38 by Andreas.
Avatar
retemirabile #9
Member since Sep 2011 · 63 posts
Group memberships: Members
Show profile · Link to this post
Thanks a lot for all your work on this.

There's one aspect that behaves a bit unexpected from my point of view: when I'm on the "Hinweise" page, I'd expect the "Artikel" tab NOT to be highlighted. (Because it isn't when I'm on the discussion page).

I'm a bit hesitant to ask because you already put so much work into this – but could this be done within a reasonable amount of time?
Avatar
Andreas (Moderator) #10
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
Quote by retemirabile:
There's one aspect that behaves a bit unexpected from my point of view: when I'm on the "Hinweise" page, I'd expect the "Artikel" tab NOT to be highlighted. (Because it isn't when I'm on the discussion page).

Let's try the following:

//"Hinweise" tab
$namespace_notes = ':hinweise:';
$_vector_tabs_left["tab-wiki-notes"]["text"]      = "Hinweise";
$_vector_tabs_left["tab-wiki-notes"]["accesskey"] = "H"; //accesskey is optional
if (!preg_match("/^".$namespace_notes."?$|^".$namespace_notes.".*?$/i", ":".getNS(getID()))){
  //The current page is a normal wiki page outside the notes namespace. Create a
  //link to the corresponding notes page. Example:
  //  - current page: "foobar"
  //  - link we are creating here: $namespace_notes."foobar"
  $_vector_tabs_left["tab-wiki-notes"]["wiki"]  = $namespace_notes.getID();
} else {
  //If the notes tab itself is the current page, link to the corresponding
  //normal wiki page instead. Example:
  //  - current page: $namespace_notes."foobar"
  //  - link we are creating here: "foobar" (to prevent a recursive notes tab.
  //    Would be $namespace_notes.$namespace_notes."foobar" without this
  //    correction)
  $_vector_tabs_left["tab-wiki-notes"]["wiki"] = ":".substr(getID(), strlen($namespace_notes)-1);
  $_vector_tabs_left["tab-wiki-notes"]["class"] = "selected";

  //Overwrite the behavior of the article tab. Normally, it would link to the
  //current notes page. We want to link the corresponding normal wiki page
  //instead to make it easy for the user to get back to the corresponding normal
  //wiki page
   $_vector_tabs_left["ca-nstab-main"]["wiki"]  = ":".substr(getID(), strlen($namespace_notes)-1);
   //de-select the the article tab (setting the class to "" would work, too. But I
   //think unsetting the whole value is more tidy)
   unset($_vector_tabs_left["ca-nstab-main"]["class"]);
}

Ok now?

Quote by retemirabile:
I'm a bit hesitant to ask because you already put so much work into this – but could this be done within a reasonable amount of time?

No problem so far :-). Especially as you are a user reading the docs, asking good questions and stuff :-p
I'm so electronic I shit bits
This post was edited on 2012-03-07, 12:00 by Andreas.
Avatar
retemirabile #11
Member since Sep 2011 · 63 posts
Group memberships: Members
Show profile · Link to this post
Excellent! Many thanks. Now it's just perfect!
Avatar
Andreas (Moderator) #12
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
I just tried it on you page... seems to be ok, but is it intentional to have "hinweise" for a discussion page? I think it would be better if I'm on the page "talk:foobar", "Hinweise" would point to the "hinweise:foobar" instead of "hinweise:talk:hinweise:foobar". If you think the same, I'll have a look at it later this day :-)
I'm so electronic I shit bits
Avatar
Andreas (Moderator) #13
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
I think the following makes more sense (I improved the comments to make it easier to follow what is going on):

//"Hinweise" tab
$namespace_notes = ':hinweise:';
$_vector_tabs_left["tab-wiki-notes"]["text"]      = "Hinweise";
$_vector_tabs_left["tab-wiki-notes"]["accesskey"] = "H"; //accesskey is optional
if (!preg_match("/^".$namespace_notes."?$|^".$namespace_notes.".*?$/i", ":".getNS(getID()))){
  //We are NOT on a notes page
  if ($vector_context !== "discuss" || !tpl_getConf("vector_discuss")){ //$vector_context was defined within main.php
    //The current page is a normal wiki page outside the notes namespace and no
    //discussion page. Therefore create a link to the corresponding notes page.
    //Example:
    //  - current page: "foobar"
    //  - link we are creating here: $namespace_notes."foobar"
    $_vector_tabs_left["tab-wiki-notes"]["wiki"]  = $namespace_notes.getID();
  } else {
    //The current page is a discussion page belonging to the normal wiki page.
    //Create a link to the corresponding notes page of the normal wiki page,
    //not a notes page for the discussion page. Example:
    //  - current page: "tpl_getConf("vector_discuss_ns").foobar"
    //  - link we are creating here: $namespace_notes."foobar"
    $_vector_tabs_left["tab-wiki-notes"]["wiki"]  = $namespace_notes.substr(getID(), strlen(tpl_getConf("vector_discuss_ns"))-1);
  }
} else {
  //We are on a notes page. Highlight/select the notes tab.
  $_vector_tabs_left["tab-wiki-notes"]["wiki"]  = ":".getID();
  $_vector_tabs_left["tab-wiki-notes"]["class"] = "selected";

  //Overwrite the behavior of the article tab. Normally, it would link to the
  //current notes page itself. We want to link the corresponding normal wiki
  //page instead to make it easy for the user to get back to the main content.
  $_vector_tabs_left["ca-nstab-main"]["wiki"]  = ":".substr(getID(), strlen($namespace_notes)-1);
  //de-select the the article tab
  unset($_vector_tabs_left["ca-nstab-main"]["class"]); //setting the class to "" would work, too. But I think unsetting the whole value is more tidy.

  if (tpl_getConf("vector_discuss")) {
    //Overwrite the behavior of the discussion tab. Normally, it would link to
    //a discussion page for the notes page. We want to link the discussion
    //page of the normal wiki page instead.
    $_vector_tabs_left["ca-talk"]["wiki"] = tpl_getConf("vector_discuss_ns").substr(getID(), strlen($namespace_notes)-1);
  }
}

The user can just switch between the main content, the corresponding discussion and/or notes. So both the discussion and notes tab are handled as some kind of "meta" pages know. I think this is the intended behaviour.
I'm so electronic I shit bits
This post was edited on 2012-03-07, 12:48 by Andreas.
Avatar
retemirabile #14
Member since Sep 2011 · 63 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #12
I think the same but I considered it too small a glitch to actually mention it ;-)
Avatar
Andreas (Moderator) #15
Member since Dec 2009 · 264 posts · Location: Karlsruhe, Germany
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
Ha, i was faster :-p

BTW: please check your forum PMs / Inbox
I'm so electronic I shit bits
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next 
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-05-26, 18:41:50 (UTC +02:00)