Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-21 14:13:54

pompilos
Member
From: Spain
Registered: 2005-06-07
Posts: 114
Website

[howto] File download name IF it hasn't title

The new feature “Title” available for <txp:file_download_name title=“1” /> is a good idea, but it creates a problem in my site.

There were more than a thousand files without title, when this feature was created, and the are some files uploaded afterwards who has a title. I want to show the title of the articles, but if I do so, the name of the old files disappear. Perhaps the solution for this problem is to change the behavior of the tag in order to do this: “If the file has a tiltle, show its title, if it hasn’t, show the name”. I didn’t find any conditional tag to do this, is there anyone? If not, can some of the developers consider to change the behavior of the tag.

Thank you in advance.

Offline

#2 2011-06-21 14:21:58

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [howto] File download name IF it hasn't title

In your form you could do something like:

<!--
	Set a variable containing the file title
-->
<txp:variable name="title" value='<txp:file_download_name title="1" />' />
<!--
	See if there is title, if not show the name
-->
<txp:if_variable name="title" value="">
	<txp:file_download_name />
<txp:else />
	<txp:variable name="title" />
</txp:if_variable>

Edit. Flipping conditionals as suggested.

Last edited by Gocom (2011-06-21 18:59:36)

Offline

#3 2011-06-21 15:56:52

ax
Plugin Author
From: Germany
Registered: 2009-08-19
Posts: 165

Re: [howto] File download name IF it hasn't title

Or, easier, submit this in phpmyadmin:

UPDATE txp_file
SET title = filename
where title is NULL

(untested)

Offline

#4 2011-06-21 18:13:45

pompilos
Member
From: Spain
Registered: 2005-06-07
Posts: 114
Website

Re: [howto] File download name IF it hasn't title

Hi, Gocom. I don’t know why, but your proposal doesn’t work on my site. The titles appear but names don’t do so. Here is the code of my form for files download, although I think there isn’t any mistake in it:

<txp:file_download_link>
<txp:variable name="title" value='<txp:file_download_name title="1" />' />
<txp:if_variable name="title" value="">
	<txp:variable name="title" />
<txp:else />
	<txp:file_download_name />
</txp:if_variable>
</txp:file_download_link>

HI, ax. I would prefer not touching the database, because I’m not very familiarized with this procedure. Indeed the new files wouldn’t show its name if the people who upload files don’t fill the Title field. Thanks anyway.

Any other suggestion

Offline

#5 2011-06-21 18:24:24

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [howto] File download name IF it hasn't title

pompilos wrote:

Hi, Gocom. I don’t know why, but your proposal doesn’t work on my site.

The condition is upside down. Title is used the when the title is empty and name when title isn’t empty. Flip the statements. I.e.

<txp:if_variable name="title" value="">
	<txp:file_download_name />
<txp:else />
	<txp:variable name="title" />
</txp:if_variable>

Last edited by Gocom (2011-06-21 18:24:51)

Offline

#6 2011-06-21 18:55:12

pompilos
Member
From: Spain
Registered: 2005-06-07
Posts: 114
Website

Re: [howto] File download name IF it hasn't title

Hi, Gocom, you are right. Now it works perfectly. Conditional tags are very difficult for me.

Perhaps it is a good idea that you edit your previous answer (#2) in order to not confusing future readers of the thread. Also, it would be nice to move this thread to the section “How to…” of the forum, but I don’t know how to make it. Do you?

Thank you very much. Textpattern community is a good place.

Offline

#7 2011-06-21 19:03:44

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [howto] File download name IF it hasn't title

pompilos wrote:

Do you?

Admins and devs can move it, if they considers it worthy.

Thank you very much. Textpattern community is a good place.

No problem. You’re very welcome :)

Last edited by Gocom (2011-06-21 19:03:53)

Offline

Board footer

Powered by FluxBB