Skip to content

Instantly share code, notes, and snippets.

@harmstyler
Created October 30, 2012 18:22
Show Gist options
  • Save harmstyler/3982019 to your computer and use it in GitHub Desktop.
Save harmstyler/3982019 to your computer and use it in GitHub Desktop.
Like if/else blocks?
{* Custom Embed template: Embed-Latest *}
{* User inserts an object, chooses embed-latest as view *}
{* Page viewer is then shown the most recent article or media_page under that object *}
{cache-block expiry=300 keys=array($object.id, $object.modified,$object.main_node_id)}
{def $article = fetch( 'content', 'list',
hash( 'parent_node_id', $object.main_node_id ,
'sort_by', array( 'published', false() ),
'class_filter_type', 'include',
'class_filter_array', array('media_page', 'article', 'link', 'blog_post'),
'limit', 1))}
{def $pubdate=false()
$img_src=false()
$img_alt=false()
$this_month=currentdate()|datetime('custom', '%F %Y')
$publication=''
$desc=''}
{if $article|count}
{set $article = $article.0}
{/if}
{* This is hack-ish, and will have to be updated. Hotlinks aren't the best strategy. *}
{if $object.name|contains('Christian Science Sentinel')}
{set $img_src='http://www.spirituality.com/sentinel/images/sentinel-cover.jpg'}
{set $img_alt='Christian Science Sentinel'}
{set $publication = 'Sentinel'}
{elseif $object.name|contains('The Christian Science Journal')}
{set $img_src='http://www.spirituality.com/journal/images/journal-cover.jpg'}
{set $img_alt='The Christian Science Journal'}
{set $publication = 'Journal'}
{elseif $object.name|contains('The Christian Science Monitor')}
{set $img_src='http://www.spirituality.com/monitor/images/monitor-cover.jpg'}
{set $img_alt='The Christian Science Monitor'}
{set $publication = 'Monitor'}
{elseif $object.name|contains('Herald')}
{set $img_src='http://www.elheraldocc.com/heraldo/images/spanish-cover.jpg'}
{set $img_alt='El Heraldo de la Ciencia Cristiana'}
{set $publication = 'Herald'}
{elseif $object.name|contains('Your Daily Lift')}
{set $img_src='DL-200x200-03.png'|ezimage(no)}
{set $img_alt='Your Daily Lift'}
{set $publication = 'Daily Lift'}
{elseif $object.name|contains('Sentinel chat')}
{set $img_src='sentinel-audio-logo.jpg'|ezimage(no)}
{set $img_alt='Sentinel Audio'}
{set $publication = 'Sentinel Audio'}
{elseif $object.name|contains('Time4Thinkers')}
{set $img_src='time4thinkers_small.jpg'|ezimage(no)}
{set $img_alt='Time4Thinkers'}
{set $publication = 'Time4Thinkers'}
{elseif $object.name|downcase()|contains('lectures')}
{set $img_src='cs-lectures-logo-small.jpg'|ezimage(no)}
{set $img_alt='Online lectures'}
{set $publication = 'Lectures'}
{else}
{* Fetching only images does not return results for some reason.
def $class=fetch( 'content', 'class', hash( 'class_id', 'image' ) )*}
{def $related_images = fetch( 'content', 'related_objects',
hash( 'object_id', $object.id ) )}
{if $related_images|count}
{foreach $related_images as $img}
{if $img.class_identifier|eq('image')}
{if null($img.data_map.image.content.small)}
<!-- {attribute_view_gui attribute=$img.data_map.image image_class='small'} -->
{/if}
{set $img_src = $img.data_map.image.content.small.url|ezurl(no)
$img_alt = $img.data_map.image.content.small.alternative_text}
{break}
{/if}
{/foreach}
{/if}
{undef $related_images}
{set $publication = $object.name}
{/if}
{* Find date, if exists. *}
{if $article.data_map.publication_date.has_content}
{set $pubdate=$article.data_map.publication_date.content.timestamp|datetime('custom','%n/%d')}
{elseif $article.data_map.media_date.has_content}
{set $pubdate=$article.data_map.media_date.content.timestamp|datetime('custom','%n/%d')}
{elseif $article.data_map.publish_date.has_content}
{set $pubdate=$article.data_map.publish_date.content.timestamp|datetime('custom','%n/%d')}
{elseif $article.object.published}
{set $pubdate=$article.object.published|datetime('custom','%n/%d')}
{/if}
{* Create description. *}
{if $article.data_map.summary.has_content}
{set $desc=$article.data_map.summary.content.output.output_text|strip_tags|wash|trim}
{elseif $article.data_map.description.has_content}
{set $desc=$article.data_map.description.content.output.output_text|strip_tags|wash|trim}
{elseif $article.data_map.body.has_content}
{set $desc=$article.data_map.body.content.output.output_text|strip_tags|wash|trim|jshsummary}
{elseif $article.data_map.byline.has_content}
{set $desc=$article.data_map.byline.content|jshmarkdown}
{else}
{set $desc=$object.name|jshmarkdown}
{/if}
{* Special case for Media Pages *}
{if $article.class_identifier|eq('media_page')}
{if $object.name|eq('Your Daily Lift')}{* Lift's use Byline for description *}
{set $desc=$article.data_map.byline.content|jshmarkdown}
{else}{* Media pages use text block for summary vs XML block for article *}
{set $desc=$article.data_map.summary.content|jshmarkdown}
{/if}
{/if}
<div class="block feed-reader">
<article class="{$article.parent.class_identifier} block-item">
{if $article.object.class_identifier|eq('link')}
<header>
{if $img_src}
<a href={$article.data_map.location.content|ezurl} title="{$article.data_map.name.content}" target="_blank">
<img src="{$img_src}" width="98" alt="{$img_alt} {$this_month}" />
</a>
{/if}
</header>
<h4 class="item-title">
<a href={$article.data_map.location.content|ezurl} title="{$article.data_map.name.content}" target="_blank">{$article.data_map.name.content}</a>
</h4>
{else}
<header>
{if $img_src}
<a href={if $article.url_alias}{$article.url_alias|ezurl(full)}{else}{$object.main_node.url|ezurl(full)}{/if} title="{if is_set($article)}{$article.data_map.title.data_text}{else}{$object.name}{/if}">
<img src="{$img_src}" width="98" alt="{$img_alt} {$this_month}" />
</a>
{/if}
</header>
<h4 class="item-title">
<a href={$article.url_alias|ezurl(full)} title="{$article.data_map.title.data_text}">{$article.data_map.title.data_text}</a>
</h4>
{/if}
<p>
<span class="byline">{$publication}{if $pubdate} {$pubdate}{/if}</span>&mdash;{$desc}
</p>
</article>
</div>
{undef $article $pubdate $desc $img_src $img_alt $this_month $publication}
{/cache-block}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment