rejetto forum
Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: D on March 15, 2021, 02:28:24 AM
-
I need folder names to have additional link attached automatically, with part of foldername in it:
Folder "A - B C 3" [link to example.site/view-2.php?name=A]
or
Folder "A - B C 3" [link to example.site/view-2.php?name=A: B C III]
1. How can I use foldername as variable?
2. How can I edit that variable? (%20- = %3A)
3. How can I add my link through diff template?
-
use %item-name% and update the value using some macros replace, substring, cut , trim .. to include the result in the url link
http://www.rejetto.com/wiki/index.php?title=HFS:_scripting_commands
-
But how do I insert my code into template? I tried:
[+folder]
%item-name%
this edits "Hits" column instead of "Name" one
Putting this into head of hfs.tpl worked for me:
<script type="text/javascript">
document.addEventListener('DOMContentLoaded',function(){
let reg1=/~img_folder"> (.*)</g;
let reg2='~img_folder"> $1 </a> [<a href="http://example.site/view-2.php?name=$1" >Info</a>]<';
document.body.innerHTML=document.body.innerHTML.replace(reg1,reg2);
let reg3=/view-2.php\?name=(.*)( \-)(.*?)">/
let reg4='view-2.php\?name=$1:$3">';
document.body.innerHTML=document.body.innerHTML.replace(reg3,reg4);
});
</script>
however it works globally, not only for folder I want.
-
If the folder you want is the current folder, that is %encoded-folder%
See also this for more macro fun: http://rejetto.com/forum/index.php?topic=12059.msg1065252#msg1065252
Separation of (additional) functions works with filetypes, users, groups. . . But not the parent folder, because the time-travel functionality was already redacted by the future developers (surely doable; but, the costs are inconvenient). ;) (not easy to separate by parent folder contents that have not yet been seen).
P.S.
The traditional way is user-group to identify special folders (before the contents have been seen). However, if you're not going with login > users > groups to differentiate, then you can use the .exec macro for diy scanner (to flag content, before the end-user arrives).
-
You asked me to elaborate what I'm trying to do.
Let's say I want to include this feature for folder "My"
(https://i114.fastpic.ru/big/2021/0316/09/18f13ba4a4e64c9c764c8cd983d6d809.png)
The script above works, but globally. I only need it for folder "My"
Editing diff template
(https://i114.fastpic.ru/big/2021/0316/4c/0c971d7a48d10b14fd701ad64ffbd74c.png)
results in this
(https://i114.fastpic.ru/big/2021/0316/ac/3563d43577a2d212eb4009945ccfe2ac.png)
-
the section [file=folder=link|private] containt the division of column name
use the totality of this text as a starting point to put in the diff template properties , instead of what you put there previously
[file=folder=link|private]
<div class='item item-type-%item-type% {.if|{.get|can access.}||cannot-access.} {.if|{.get|can archive item.}|can-archive.}'>
<div class="item-link">
<a href="%item-url%">
<img src="%item-icon%" />
%item-name%
</a>
{.if|{.=|%item-type%|folder.}|{:[<a href="http://example.site/view-2.php?name={.encode html|%item-name%.}"> Info </a>]:}.}
</div>
<div class='item-props'>
<span class="item-ts"><i class='fa fa-clock-o'></i></span>
[+file]
<span class="item-size"><i class='fa fa-download' title="{.!Download counter:.} %item-dl-count%"></i> %item-size%B</span>
[+file=folder=link]
{.if|{.get|is new.}|<i class='fa fa-star' title="{.!NEW.}"></i>.}
[+file=folder]
<button class='item-menu pure-button' title="More options"><i class="fa fa-bars"></i></button>
[+file=folder=link]
</div>
<div class='clearer'></div>
[+file=folder=link]
{.if| {.length|{.?search.}.} |{:{.123 if 2|<div class='item-folder'>{.!item folder.} |{.breadcrumbs|{:<a href="%bread-url%">%bread-name%/</a>:}|from={.count substring|/|%folder%.}/breadcrumbs.}|</div>.}:} .}
{.123 if 2|<div class='comment'><i class="fa fa-quote-left"></i><span class="comment-text">|{.commentNL|%item-comment%.}|</span></div>.}
</div>
-
You asked me to elaborate what I'm trying to do....
Kudos for that.
Unfortunately, I'm a bit daft and didn't manage to get past editing of an older template which was slow and so huge that the editing is difficult. Maybe it would be good to use something more streamlined? For example, the Takeback template has a lot of features but also more speed and less bulk.
-
alt. without macros
[+]
<script>
[...document.querySelectorAll('#files a[href$="/"]')].forEach(item =>
item.insertAdjacentHTML('afterend', '<a href="http://example.site/view-2.php?name='+item.innerText.trim()+'"> Info </a>')
)
</script>
-
[+]
<script>
[...document.querySelectorAll('#files a[href$="/"]')].forEach(item =>
item.insertAdjacentHTML('afterend', '<a href="http://example.site/view-2.php?name='+item.innerText.trim()+'"> Info </a>')
)
</script>
godsend