Jump to content

Custom multiple upload field in Pages


hjmaier

Recommended Posts

Posted

Dear all,

I have a custom upload field in Pages, called anhang (it was a migration from IPS 3.4). 

I am struggling a bit to figure out the correct Display Custom Format.

What I want to archive:

1. Have a separate line for each download

2. I want to see the correct file name and not the whole URL. 

I tried something like this according to a topic I found here:

{{$anhang = $record->customFieldDisplayByKey('anhang', 'raw');}}
{{foreach $anhang as $anhang_url}}
<br/>
<a href="{$anhang_url}">{$anhang_url}</a>
{{endforeach}}

But this of course shows me only the "real" url and not the attachment name:

Unbenannt.thumb.PNG.85b6385f662a3e39c572ca8fe07291dd.PNG

The url should look like something like this:

http://www.midgard-forum.de/forum/applications/cms/interface/file/file.php?record=1593&database=1&file=monthly_04_2017%2F2016%252011%2520Midgard%2520Lernkosten%2520Zauberschutz%2520und%2520Zaubermittel%2520M5%2520v1.21.ods.413025493ee2e741b72bddabd2f4b0b1

Any idea how I can solve my problem?

Posted

You can get the raw content of the field through $record->field_XXX, where XXX is the field ID. In a multi-upload field, the upload URLs are comma separated, so you can do $image_exploded = explode(',',$record->field_XXX) and then loop through it. 

Not really sure though why you do that i the template and not in the field settings and why you seem to want to construct the entries manually. That sounds rather cumbersome, but I am not sure what you are trying to achieve. 

Posted

@opentype Sorry, I meant the field options.

I tried to put it here:

58f1f18122adb_Bildschirmfoto2017-04-15um12_06_26.thumb.png.395eeb98029095769244bd7084ba8186.png

But it did not give me the result I wanted. 

{$formValue} and {$value} give me something like this (only the text with no link):

58f1f2332fc13_Bildschirmfoto2017-04-15um12_12_17.thumb.png.f689bca31fac5ff6d431f85bced016c0.png

 

Posted

$record is for the template, not the field options. In the field options, do something like this:

{{if $formValue}}
{{$anhaenge = explode(',',$formValue);}}
{{foreach $anhaenge as $anhang}}
<p><a href="{file='$anhang' extension='cms_records'}">{$anhang}</a></p>
{{endforeach}}
{{endif}}

 

Posted

@opentype

Thank you! It is almost what I want to archive. There are two issues left:

The link is: 

http://www.midgard-forum.de/forum/uploads/monthly_04_2017/2016%2011%20Midgard%20Lernkosten%20Zauberschutz%20und%20Zaubermittel%20M5%20v1.21.ods.413025493ee2e741b72bddabd2f4b0b1

But it should be:

http://www.midgard-forum.de/forum/applications/cms/interface/file/file.php?record=1593&database=1&file=monthly_04_2017%2F2016%252011%2520Midgard%2520Lernkosten%2520Zauberschutz%2520und%2520Zaubermittel%2520M5%2520v1.21.ods.413025493ee2e741b72bddabd2f4b0b1

I don't allow deep links, since I want to have an authority check.

The second issue is the file name. Can I have the file name instead of the path to that file?

Posted

Thank you again. It works almost.

The following part should be built dynamically:

http://www.midgard-forum.de/forum/applications/cms/interface/file/file.php?record=1593&database=1

Since the record ID is the Record number from a specific article. I could live with the fixed URL and database=1, since it looks for every article the same, but the record ID will change with every article. 

And: Is there a way to retrieve the file name itself? 

Posted
14 minutes ago, opentype said:

Just the file name is in {$anhang} of course. 

In {$anhang} is not the filename. It is the "internal" name. It looks like this:

monthly_04_2017/2016 11 Midgard Lernkosten Zauberschutz und Zaubermittel M5 v1.21.ods.413025493ee2e741b72bddabd2f4b0b1

While the filename is:

2016 11 Midgard Lernkosten Zauberschutz und Zaubermittel M5 v1.21.ods

But thank you for your help! I don't want to sound too demanding.

Posted

@opentypes code should work.

So, when you use

<p><a href="{file='$anhang' extension='cms_records'}">{$anhang}</a></p>

it returns

http://www.midgard-forum.de/forum/uploads/monthly_04_2017/2016%2011%20Midgard%20Lernkosten%20Zauberschutz%20und%20Zaubermittel%20M5%20v1.21.ods.413025493ee2e741b72bddabd2f4b0b1

 

What's wrong with this? Do you need

http://www.midgard-forum.de/forum/applications/cms/interface/file/file.php?record=1593&database=1

because of the permission check?

 

 

 

Posted
27 minutes ago, hjmaier said:

In {$anhang} is not the filename. It is the "internal" name.

No, there is no internal name. There is just one filename, which is directly saved and accessed in the Pages database. It’s not a pretty name meant to be shown to users, but that’s the way it is in 4.x. 

Posted

@Daniel F

Yes. For the permission check.

The code @opentype posted works, beside the problem with the record number and the "real" filename. I checked that on my site. Here a screenshot:

Unbenannt.thumb.PNG.ce4d673a02bf08207edde31675d21bda.PNG

It shows me the "internal" filename. 

That is being pulled from the cms_custom_database_1 table:

Unbenannt1.thumb.PNG.eee638160a21ee79f9feb184c868dc8a.PNG

The "real" filename is in the core attachment table:

Unbenannt3.thumb.PNG.e08a406d9fadb9e804060e98b15ccb19.PNG

If it isn't possible to retrieve that filename, I can live with that. But well, it looks ugly.

Thank you for your help :) 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...