Features / Usability

Features / Usability

Enable File View Instead of File Download

posts: 758 United States

Tiki 15LTS

I have been scratching my head on this one since I have started using Tiki, and I am just now feeling like it's an issue I need to deal with now. Is there a way to make a file view-able in Category view mode, instead of the default download file prompt?
If you visit the link above, you'll be taken to a category view mode, and if you click on the file name "Horizontal Log Band Mill (Carpentry And Joinery, 1925)" the download prompt will activate, is there a way to set it so when you click on the file, it will view instead of download?
Thanks folks

posts: 1563 Germany

The link in the template might need adjustion.

1. Find the correct template where the output of this page (category objects list thingi) is created

2. copy to /themes/yourtheme/templates

3. mention the filename and original path here

4. let one of us try to figure out, which code to replace with wich code (should be simply a line)

5. replace, test, back to 4 until it works, then 6

6. let's think about if that would be a good optional setting for all users or if not it could go to themes.tiki.org somewhere between Template+Tricks and Themes+Shop

Just thnking ... :-)

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>


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.


posts: 758 United States

Gents, I need to digest what I just read, it's over my head!biggrin
And overwhelming. I am sorry for opening this can of worms.