Page 1 of 1
Help with using capture in News Module
Posted: Thu Jul 24, 2014 11:30 am
by becfret
Hi,
I've managed to use capture to get Open Graphs and Twitter Cards to work with the News Module for title, description etc... but I can not get it to work for images. I'm using the following in the News Template:
Code: Select all
{capture name="facebookphoto" assign="fbphoto"}{$entry->file_location}/{$field->value}{/capture}
but all it captures is:
/uploads/news/id28/
Any suggestions?
Thanks,
Becky
Re: Help with using capture in News Module
Posted: Thu Jul 24, 2014 11:42 am
by velden
Better post the whole News detail template here.
Re: Help with using capture in News Module
Posted: Thu Jul 24, 2014 1:08 pm
by becfret
Hi,
Here's all of the template:
Code: Select all
{* set a canonical variable that can be used in the head section if process_whole_template is false in the config.php *}
{capture name="facebooktext" assign="fbtitle"}{$entry->title}{/capture}
{capture name="facebooknewstext" assign="fbdescription"}{eval var=$entry->summary}{/capture}
{capture name="facebookphoto" assign="fbphoto"}{$entry->file_location}/{$field->value}{/capture}
{if isset($entry->canonical)}
{assign var='canonical' value=$entry->canonical}
{/if}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="newsPhoto">
{if $field->type == 'file'}
{* this template assumes that every file uploaded is an image of some sort, because News doesn't distinguish *}
<img src='{$entry->file_location}/{$field->value}' alt='' />
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
<h2>{$entry->title|cms_escape:htmlall}</h2>
<p class='postedby'>
{if $entry->author}
<span class='author'><strong>{$author_label}</strong> {$entry->authorname}</span>
{/if}
{if $entry->postdate}
<span class='day'> {$entry->postdate|cms_date_format}</span>
{/if}
</p>
<p>
{eval var=$entry->content}
{if $entry->extra}
{$extra_label} {$entry->extra}
{/if}
</p>
{if $return_url != ""}
<div id="NewsPostDetailReturnLink">{$return_url}</div>
{/if}
Becky
Re: Help with using capture in News Module
Posted: Thu Jul 24, 2014 1:45 pm
by velden
You're using the $field variable while it's not yet there.
Code: Select all
{foreach from=$entry->fields item='field'}...{/foreach}
As you can see the foreach loop 'creates' the $field variable.
You could move your code to just before or after this line:
Code: Select all
<img src='{$entry->file_location}/{$field->value}' alt='' />
Example:
Code: Select all
...
<img src='{$entry->file_location}/{$field->value}' alt='' />
{capture name="facebookphoto" assign="fbphoto"}{$entry->file_location}/{$field->value}{/capture}
...
[SOLVED] Re: Help with using capture in News Module
Posted: Thu Jul 24, 2014 3:41 pm
by becfret
You are a superstar! Thank you so much, works perfectly
