Last active
August 13, 2019 23:27
-
-
Save TheBrotherFromASouthernMother/c888b5757e6ccb941750b8e31fe27b34 to your computer and use it in GitHub Desktop.
Trying to conditionally render a petition card image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code before changes (compiles and shows petition image): | |
``` | |
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn -> | |
%img{src: "{{petition.photo_url}}", class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'} | |
``` | |
Attempt 1 (throws error): | |
``` | |
- if '{{petition.photo_url}}' do | |
- img_url = '{{petition.photo_url}}' | |
- else | |
- img_url = "https://static.change.org/carousel/hands-raised.jpg" | |
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn -> | |
%img{src: img_url, class: 'petition-centered-img-lg',} | |
``` | |
Attempt 2 (Compiles but does not render photo): | |
``` | |
- if '{{petition.photo_url}}' do | |
- img_url = '{{petition.photo_url}}' | |
- else | |
- img_url = "https://static.change.org/carousel/hands-raised.jpg" | |
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn -> | |
%img{src: "{{img_url}}", class: 'petition-centered-img-lg'} | |
``` | |
Attempt 3 (compiles and renders photo): | |
``` | |
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn -> | |
%img{src: "https://static.change.org/carousel/hands-raised.jpg", class: 'petition-centered-img-lg'} | |
``` | |
Attempt 4 (compiles but does not render photo): | |
``` | |
-img_url = "https://static.change.org/carousel/hands-raised.jpg" | |
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn -> | |
="{% if petition.photo_url %}" | |
%img{src: "{{petition.photo_url}}", class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'} | |
="{% else %}" | |
%img{src: "{{img_url}}", class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'} | |
="{% endif %}" | |
``` | |
Attempt 5 (throws error): | |
``` | |
-img_url = "https://static.change.org/carousel/hands-raised.jpg" | |
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn -> | |
="{% if petition.photo_url %}" | |
%img{src: "{{petition.photo_url}}", class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'} | |
="{% else %}" | |
%img{src: img_url, class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'} | |
="{% endif %}" | |
``` | |
Attempt 6 (throws error): | |
``` | |
-img_url = "https://static.change.org/carousel/hands-raised.jpg" | |
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn -> | |
="{% if petition.photo_url %}" | |
%img{src: "{{petition.photo_url}}", class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'} | |
="{% else %}" | |
%img{src: {{img_url}}, class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'} | |
="{% endif %}" | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment