Loading...
 
Features / Usability

Features / Usability


Re: Enable File View Instead of File Download

posts: 214

The template used is: templates/tiki-browse_categories.tpl, but making the desired change is not as easy as you would hope. Instead of the template creating the url from the fileId, the template is passed an array which contains the link already coded. The template just inserts the link it is given into an href= statement.

The array passed to the template for each item listed has one or two urls, depending on the sefurl setting. If sefurl is turned on, both $objects[ix].sefurl and $objects[ix].href are passed. And if sefurl is not turned on, only $objects[ix].href is passed.

For the page in the example given (sefurl is turned on), the $objects[ix].sefurl array entry contains: "http://(domain name)/dl25", and the the $objects[ix].href array entry contains: "http://(domain name)/tiki-download_file.php?fileId=25" (the href version of the link isn't used so you don't see it).

The template only gets to choose which array variable to plug in, you don't have the option of changing the format of the link in the template.

But you can still change the link from "dl" to "display" using smarty. The line of code to change is:

Copy to clipboard
<a class="catname" href="{if empty($objects[ix].sefurl)}{$objects[ix].href}{else}{$objects[ix].sefurl}{/if}">

To change it so the link uses "display" where it is passed "dl", you can append "&display" to the non sefurl version (only if $objects[ix].type is "file", you don't want to append "&display" to non file downloads),
and use smarty regex_replace to reformat the sefurl version to be "display" instead of "dl" in the $objects[ix].sefurl.

As Torsten recommended, copy templates/tiki-browse_categories.tpl to your theme templates folder. I used the default bootstrap theme, so I copied it to themes/default/templates/.

Replace the line of code above with this line:

Copy to clipboard
<a class="catname" href="{if empty($objects[ix].sefurl)}{$objects[ix].href}{if $objects[ix].type eq 'file'}&display{/if}{else}{$objects[ix].sefurl|regex_replace:"/\/dl([0-9]+)\$/":"/display\$1"}{/if}">


Then all the file links will use the display option.

Or, if you wanted to offer them a choice of download or display, you could do replace these 3 lines:

Copy to clipboard
<a class="catname" href="{if empty($objects[ix].sefurl)}{$objects[ix].href}{else}{$objects[ix].sefurl}{/if}"> {$objects[ix].name|escape|default:' '} </a>

with:

Copy to clipboard
{if $objects[ix].type eq 'file'} {$objects[ix].name|escape|default:' '} <a class="catname" href="{if empty($objects[ix].sefurl)}{$objects[ix].href}&display{else}{$objects[ix].sefurl|regex_replace:"/\/dl([0-9]+)\$/":"/display\$1"}{/if}" title="display"> <span class="glyphicon glyphicon-open-file"></span></a> <a class="catname" href="{if empty($objects[ix].sefurl)}{$objects[ix].href}{else}{$objects[ix].sefurl}{/if}" title="download"> <span class="glyphicon glyphicon-save-file"></span></a> {else} <a class="catname" href="{if empty($objects[ix].sefurl)}{$objects[ix].href}{else}{$objects[ix].sefurl}{/if}"> {$objects[ix].name|escape|default:' '} </a> {/if}

You might want to use different glyphicons or just use "Display" and "Download" as the links.

That line of code in the tpl file had a minor change to it in Tiki 14, but remained the same in Tiki 9 through 13, so the same change could be made in earlier versions of the tiki-browse_categories.tpl.
If you are making the change in versions earlier than Tiki 14, you will have to replace the glyphicons with something else.

Tom

There are no comments at this time.

Upcoming Events

1)  18 Apr 2024 14:00 GMT-0000
Tiki Roundtable Meeting
2)  16 May 2024 14:00 GMT-0000
Tiki Roundtable Meeting
3)  20 Jun 2024 14:00 GMT-0000
Tiki Roundtable Meeting
4)  18 Jul 2024 14:00 GMT-0000
Tiki Roundtable Meeting
5)  15 Aug 2024 14:00 GMT-0000
Tiki Roundtable Meeting
6)  19 Sep 2024 14:00 GMT-0000
Tiki Roundtable Meeting
7) 
Tiki birthday
8)  17 Oct 2024 14:00 GMT-0000
Tiki Roundtable Meeting
9)  21 Nov 2024 14:00 GMT-0000
Tiki Roundtable Meeting
10)  19 Dec 2024 14:00 GMT-0000
Tiki Roundtable Meeting