Jump to content

If statements in db templates


MeekelTM

Recommended Posts

Posted

I'm trying to allow our writers to upload MP4 files and image files as part of a featured image field we use. Is there a way to use the {{if}} statement as per below however changing the first line to check if the value ends with a specific file format? Is it possible to use raw PHP at all?

I was referring to https://community.invisionpower.com/4docs/advanced-usage/development/template-logic-r73/ to see if I could come up with something however kept getting an error. 

 

{{if $value}}
	<img src="{$value}" width="335px" />
{{elseif}}
	<video width="335" height="188" autoplay loop>
  		<source src="{$value}" type="video/mp4">
		Your browser does not support the video tag.
	</video>
{{endif}}

 

Posted

Got it working in the end. Slightly easier than I thought:

{{if (substr($value, -4) == '.mp4') }}
	<video width="335" height="188" autoplay loop>
  		<source src="{$value}" type="video/mp4">
		Your browser does not support the video tag.
	</video>
{{else}}
  	<img src="{$value}" width="335px" />
{{endif}}

 

Archived

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

  • Recently Browsing   0 members

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