Created
July 13, 2020 13:21
-
-
Save cherrykoda/ff6d989094bcd3662cc0d4b7a4d7c9c8 to your computer and use it in GitHub Desktop.
[Medium] Macros v. Partials - Action Macro
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
{# This file contains macros for calculating text values #} | |
{## | |
# CREATE RESOURCE ACTION | |
# - Creates an unlinked span of text for use on cards etc. | |
# | |
# @param resource | |
# An entry object, i.e. an Activity or Resource | |
# | |
# Required Fields: resourceType (dropdown) | |
#} | |
{% macro createResourceAction(resource) %} | |
{% set type = resource.resourceType %} | |
{% if type == 'video' %} | |
<span class="button -simple">Watch the Video</span> | |
{% elseif type == 'audio' %} | |
<span class="button -simple">Listen Now</span> | |
{% elseif type == 'recipe' %} | |
<span class="button -simple">Get the Recipe</span> | |
{% elseif type == 'pdf' or type == 'article' %} | |
<span class="button -simple">Read the {{ type.label }}</span> | |
{% elseif type == 'letter' %} | |
<span class="button -simple">Read the {{ type.label }}</span> | |
{% elseif type == 'website' or type == 'other' %} | |
<span class="button -simple">Learn More</span> | |
{% endif %} | |
{% endmacro %} | |
{## | |
# CREATE LINKED RESOURCE ACTION | |
# - Creates a link using text to the item's detail page, offsite link, or file link based on the object's resource type | |
# | |
# @param resource | |
# An entry object, i.e. an Activity or Resource | |
# | |
# Required Fields: resourceType (dropdown), resourceLink (plaintext) OR resourceFile (asset) | |
#} | |
{% macro createLinkedResourceAction(resource) %} | |
{% import '_macros/action.twig' as _self %} | |
{% set link = _self.determineResourceLink(resource) %} | |
{% set type = resource.resourceType %} | |
{% if type == 'video' %} | |
<a class="button -simple" href="{{ link }}">Watch Now</a> | |
{% elseif type == 'audio' %} | |
<a class="button -simple" href="{{ link }}">Listen Now</a> | |
{% elseif type == 'recipe' %} | |
<a class="button -simple" href="{{ link }}">Get the Recipe</a> | |
{% elseif type == 'pdf' or type == 'article' or type == 'letter' %} | |
<a class="button -simple" href="{{ link }}">Read Now</a> | |
{% elseif type == 'website' or type == 'other' %} | |
<a class="button -simple" href="{{ link }}">Learn More</a> | |
{% endif %} | |
{% endmacro %} | |
{## | |
# CREATE RESOURCE BUTTON | |
# - Creates a linked button based on the resource type, and provided offsite or file link | |
# | |
# @param resource | |
# An entry object, i.e. an Activity or Resource | |
# | |
# Required Fields: resourceType (dropdown), resourceLink (plaintext) OR resourceFile (asset) | |
#} | |
{% macro createResourceButton(resource) %} | |
{% import '_macros/action.twig' as _self %} | |
{% set link = resource.type == 'directFile' ? resource.resourceFile[0].url : resource.resourceLink %} | |
{% set type = resource.resourceType %} | |
{% if resource.type == 'onsiteContent' %} | |
<a class="button" href="{{ link }}">Read the PDF</a> | |
{% elseif type == 'video' %} | |
<a class="button" href="{{ link }}">Watch the Video</a> | |
{% elseif type == 'audio' %} | |
<a class="button" href="{{ link }}">Listen Now</a> | |
{% elseif type == 'recipe' %} | |
<a class="button" href="{{ link }}">Get the Recipe</a> | |
{% elseif type == 'pdf' or type == 'article' %} | |
<a class="button" href="{{ link }}">Read the {{ type.label }}</a> | |
{% elseif type == 'letter' %} | |
<a class="button" href="{{ link }}">Read the {{ type.label }}</a> | |
{% elseif type == 'website' or type == 'other' %} | |
<a class="button" href="{{ link }}">Learn More</a> | |
{% endif %} | |
{% endmacro %} | |
{## | |
# DETERMINE RESOURCE LINK | |
# - Returns a url based on whether the provided entry object utilizes a detail page, pdf asset, or offsite link. | |
# | |
# @param resource | |
# An entry object, i.e. an Activity or Resource | |
# | |
# Required Fields: resourcePageContent (richtext) OR resourceLink (plaintext) OR resourceFile (asset) | |
#} | |
{% macro determineResourceLink(resource) %} | |
{% set type = resource.type %} | |
{% if resource.resourcePageContent|length %} | |
{{ resource.url }} | |
{% elseif type == 'directFile' %} | |
{{ resource.resourceFile[0].url }} | |
{% else %} | |
{{ resource.resourceLink }} | |
{% endif %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment