2014-06-25 5 views
1

특정 파일 이름을 사용할 때 훌륭한 저작물이 존재하는지 확인하기 위해 이전 게시물을 따라 왔습니다.Symfony2 - 이미지 유형이 존재하는지 확인하기

Symfony2 and Twig - Check if an asset exists

그러나 대신 특정 이미지 파일 이름을 확인하는, 어떻게 당신은 이미지 유형을 확인합니까? 합니다 (.JPG 확장자를 가진 모든 파일)

예 : * .JPG (작동하지 둘 .JPG을 수행하지 않음)

{% if asset_exists('/images/*.jpg') %} 
    <div class="entry-thumbnail"> 
      <img width="230" height="172" src="{{ asset(['images/', post.image]|join) }}" class="" alt=""/> 
    </div> 
{% endif %} 

답변

0

사용중인 같이

{{ asset(['images/', post.image]|join) }}` 

왜 사용하지 :

{% if asset_exists(['images/', post.image]|join) %} 

팁 : concat operator ~를 사용하여 ['images/', post.image]|join 대체 : 'images/' ~ post.image

0

당신은 나뭇 가지 확장을 수정해야하고 count(glob($toCheck)) < 1!is_file($toCheck)을 대체 할 것 즉시

glob function (php.net)

관련 문제