私は<img src="x" />
が表示されていないとしましょう<img src="y">
を表示したいのですがこれは可能ですか?htmlでifやelseを使うにはどうしたらいいですか?
編集:質問が混乱している場合
申し訳ありません... 問題はこれです:ユーザーがURLを挿入すると、そのURLがユーチューブへのリンクである場合は、ユーチューブのサムネイルを表示する必要があります。そのURLがYouTube動画へのリンクでない場合、post.image(デフォルト画像)を表示する必要があります。しかし、post.imageは表示されません!
//表示post.image
上記の二つの画像を表示するの罰金。 {{post.thumbnail}}がnoneの場合、{{post.image}}を表示したいのですが...どうすればいいですか?私はそれを必要とする理由です
,,あなたは、あなたのHTMLファイルにJavaScriptを記述し、機能させることができ、以下のコード
<td>
{% if post.main_image %} //if post has main_image
<img src="{{post.get_image_url}}" class="img-rounded" alt="☺" height="75" width="75"/>//display that image
{% elif post.url %}//if post has url
{% video post.url as my_video %} //setting post.url as my_video(problem starts here I think)
{% if my_video %} //if my_video is there
<img src="{{ my_video.thumbnail }}" class="img-rounded" alt="☺" height="75" width="75"/> //display the video thumbnail
{% else %} //if my_video isn't there and post.url isn't a link to youtube
<img src="{{post.image}}" class="img-rounded" alt="☺ " height="75" width="75"/> //display post.image
{% endif %}
{% endvideo %}
{% else %}
<img src="{{post.thumbnail}}" class="img-rounded" alt="☺" height="75" width="75"/>
{% endif %}
</td>
so main thing to look at it is for post.url if I don't have <img src="{{ my_video.thumbnail }}" class="img-rounded" alt="☺" height="75" width="75"/> I want
<img src="{{post.image}}" class="img-rounded" alt="☺ " height="75" width="75"/> //display post.image
画像がロードできない、つまりその場所/ URLなどに画像が存在しない場合、代わりに別の画像を読み込むことを意味します。 – adeneo
@adeneo noを使っていません。もし存在すれば、私がやろうとしているのですか。 –
いいえ、HTMLは論理的ではありません。これにはJavaScriptを使用する必要があります。 – undefined