Hi there!
I have an editable region which is type='file'. I would like to be able to then display different things on the webpage depending on the type of file uploaded into this region. I was hoping to catch the two main types, with a fallback 'else' for downloading the file if it doesn't match one of the two main types. Therefore, what I was hoping to code was:
<if extension = .pdf>
<iframe for displaying pdf>
<else />
<if extension = .html>
<iframe for displaying html>
<else />
<href download file>
</if>
</if>
I am pretty confident that I can do all of this, except for the initial step of querying the extension of the file once it is uploaded. I have tried to use regex, but I don't really know how to make it work within a couchcms tag. At its most basic I have tried
Simply because I came across a similar use of regex in the documentation for the 'validator' field of the editable tag. I have played around with it, but it just never returns true so I feel like it is simply not using the regex.
Is it possible, with cms:if or cms:set to query the extension? I did also wonder if I could do something like
But I am not aware of how I would 'cut' the file string to just the last 4 characters?
Any help on this would be much appreciated.
Best
Anthony
I have an editable region which is type='file'. I would like to be able to then display different things on the webpage depending on the type of file uploaded into this region. I was hoping to catch the two main types, with a fallback 'else' for downloading the file if it doesn't match one of the two main types. Therefore, what I was hoping to code was:
<if extension = .pdf>
<iframe for displaying pdf>
<else />
<if extension = .html>
<iframe for displaying html>
<else />
<href download file>
</if>
</if>
I am pretty confident that I can do all of this, except for the initial step of querying the extension of the file once it is uploaded. I have tried to use regex, but I don't really know how to make it work within a couchcms tag. At its most basic I have tried
- Code: Select all
<cms:if uploaded_file = 'regex=.*\.pdf$'>
Simply because I came across a similar use of regex in the documentation for the 'validator' field of the editable tag. I have played around with it, but it just never returns true so I feel like it is simply not using the regex.
Is it possible, with cms:if or cms:set to query the extension? I did also wonder if I could do something like
- Code: Select all
<cms:set uploaded_file_extension = (last four characters of uploaded_file string)><cms:if uploaded_file_extension == '.pdf'>
But I am not aware of how I would 'cut' the file string to just the last 4 characters?
Any help on this would be much appreciated.
Best
Anthony